Skip to content

Commit

Permalink
JuliaLang#11105 Add syntax errors for unsigned literals where used to…
Browse files Browse the repository at this point in the history
… get promoted to signed
  • Loading branch information
ScottPJones committed May 4, 2015
1 parent a584bb7 commit 6b45b63
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
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)

@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

0 comments on commit 6b45b63

Please sign in to comment.