Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#11105 Add syntax errors for unsigned literals > UInt128 #11130

Merged
merged 1 commit into from
May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
((<= l 32) (uint32 n))
((<= l 64) (uint64 n))
((<= l 128) `(macrocall @uint128_str ,s))
(else `(macrocall @big_str ,s)))))
(else (error "Hex or binary literal too large for UInt128")))))

(define (sized-uint-oct-literal n s)
(if (string.find s "o0")
Expand All @@ -354,7 +354,7 @@
(else (uint64 n)))
(if (oct-within-uint128? s)
`(macrocall @uint128_str ,s)
`(macrocall @big_str ,s)))))
(error "Octal literal too large for UInt128")))))

(define (strip-leading-0s s)
(define (loop i)
Expand Down
36 changes: 21 additions & 15 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,8 @@ end
@test isa(0b0000000000000000000000000000000000000000000000000000000000000000,UInt64)
@test isa(0b00000000000000000000000000000000000000000000000000000000000000000,UInt128)
@test isa(0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,UInt128)
@test isa(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,BigInt)
#@test isa(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,BigInt)
@test_throws ParseError parse("0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
@test isa(0b11111111,UInt8)
@test isa(0b111111111,UInt16)
@test isa(0b1111111111111111,UInt16)
Expand All @@ -1662,7 +1663,8 @@ end
@test isa(0b1111111111111111111111111111111111111111111111111111111111111111,UInt64)
@test isa(0b11111111111111111111111111111111111111111111111111111111111111111,UInt128)
@test isa(0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,UInt128)
@test isa(0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,BigInt)
#@test isa(0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,BigInt)
@test_throws ParseError parse("0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")

# octal literals

Expand All @@ -1680,7 +1682,8 @@ end
@test isa(0o000000000000000000000,UInt64)
@test isa(0o0000000000000000000000,UInt128)
@test isa(0o000000000000000000000000000000000000000000,UInt128)
@test isa(0o0000000000000000000000000000000000000000000,BigInt)
#@test isa(0o0000000000000000000000000000000000000000000,BigInt)
@test_throws ParseError parse("0o0000000000000000000000000000000000000000000")
@test isa(0o11,UInt8)
@test isa(0o111,UInt8)
@test isa(0o11111,UInt16)
Expand All @@ -1691,10 +1694,10 @@ end
@test isa(0o1111111111111111111111,UInt64)
@test isa(0o111111111111111111111111111111111111111111,UInt128)
@test isa(0o1111111111111111111111111111111111111111111,UInt128)
@test isa(0o11111111111111111111111111111111111111111111,BigInt)
@test 0o4000000000000000000000000000000000000000000 ==
340282366920938463463374607431768211456

#@test isa(0o11111111111111111111111111111111111111111111,BigInt)
@test_throws ParseError parse("0o11111111111111111111111111111111111111111111")
#@test 0o4000000000000000000000000000000000000000000 ==
# 340282366920938463463374607431768211456
# hexadecimal literals

@test isa(0x00,UInt8)
Expand All @@ -1706,7 +1709,8 @@ end
@test isa(0x0000000000000000,UInt64)
@test isa(0x00000000000000000,UInt128)
@test isa(0x00000000000000000000000000000000,UInt128)
@test isa(0x000000000000000000000000000000000,BigInt)
#@test isa(0x000000000000000000000000000000000,BigInt)
@test_throws ParseError parse("0x000000000000000000000000000000000")
@test isa(0x11,UInt8)
@test isa(0x111,UInt16)
@test isa(0x1111,UInt16)
Expand All @@ -1716,7 +1720,8 @@ end
@test isa(0x1111111111111111,UInt64)
@test isa(0x11111111111111111,UInt128)
@test isa(0x11111111111111111111111111111111,UInt128)
@test isa(0x111111111111111111111111111111111,BigInt)
#@test isa(0x111111111111111111111111111111111,BigInt)
@test_throws ParseError parse("0x111111111111111111111111111111111")

# "-" is not part of unsigned literals
@test -0x10 == -(0x10)
Expand All @@ -1729,17 +1734,18 @@ end
@test -0o0000000000000000000001 == -(0o0000000000000000000001)
@test -0b00000000000000000000000000000000000000000000000000000000000000001 ==
-(0b00000000000000000000000000000000000000000000000000000000000000001)
@test -0x000000000000000000000000000000001 == -(0x000000000000000000000000000000001)
@test -0o0000000000000000000000000000000000000000001 ==
-(0o0000000000000000000000000000000000000000001)
@test -0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 ==
-(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
#@test -0x000000000000000000000000000000001 == -(0x000000000000000000000000000000001)
#@test -0o0000000000000000000000000000000000000000001 ==
# -(0o0000000000000000000000000000000000000000001)
#@test -0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 ==
# -(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like just deleting these would be better, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sure, will do... thanks!


@test isa(-0x00,UInt8)
@test isa(-0x0000000000000000,UInt64)
@test isa(-0x00000000000000000,UInt128)
@test isa(-0x00000000000000000000000000000000,UInt128)
@test isa(-0x000000000000000000000000000000000,BigInt)
#@test isa(-0x000000000000000000000000000000000,BigInt)
@test_throws ParseError parse("-0x000000000000000000000000000000000")

# Float32 literals
@test isa(1f0,Float32)
Expand Down