Skip to content

Commit b6904b6

Browse files
committed
Merge pull request #11130 from ScottPJones/spj/hexoctlit
#11105 Add syntax errors for unsigned literals > UInt128
2 parents e28ed6d + 6b45b63 commit b6904b6

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/julia-parser.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@
342342
((<= l 32) (uint32 n))
343343
((<= l 64) (uint64 n))
344344
((<= l 128) `(macrocall @uint128_str ,s))
345-
(else `(macrocall @big_str ,s)))))
345+
(else (error "Hex or binary literal too large for UInt128")))))
346346

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

359359
(define (strip-leading-0s s)
360360
(define (loop i)

test/numbers.jl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,8 @@ end
16521652
@test isa(0b0000000000000000000000000000000000000000000000000000000000000000,UInt64)
16531653
@test isa(0b00000000000000000000000000000000000000000000000000000000000000000,UInt128)
16541654
@test isa(0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,UInt128)
1655-
@test isa(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,BigInt)
1655+
#@test isa(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,BigInt)
1656+
@test_throws ParseError parse("0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
16561657
@test isa(0b11111111,UInt8)
16571658
@test isa(0b111111111,UInt16)
16581659
@test isa(0b1111111111111111,UInt16)
@@ -1662,7 +1663,8 @@ end
16621663
@test isa(0b1111111111111111111111111111111111111111111111111111111111111111,UInt64)
16631664
@test isa(0b11111111111111111111111111111111111111111111111111111111111111111,UInt128)
16641665
@test isa(0b11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,UInt128)
1665-
@test isa(0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,BigInt)
1666+
#@test isa(0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111,BigInt)
1667+
@test_throws ParseError parse("0b111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")
16661668

16671669
# octal literals
16681670

@@ -1680,7 +1682,8 @@ end
16801682
@test isa(0o000000000000000000000,UInt64)
16811683
@test isa(0o0000000000000000000000,UInt128)
16821684
@test isa(0o000000000000000000000000000000000000000000,UInt128)
1683-
@test isa(0o0000000000000000000000000000000000000000000,BigInt)
1685+
#@test isa(0o0000000000000000000000000000000000000000000,BigInt)
1686+
@test_throws ParseError parse("0o0000000000000000000000000000000000000000000")
16841687
@test isa(0o11,UInt8)
16851688
@test isa(0o111,UInt8)
16861689
@test isa(0o11111,UInt16)
@@ -1691,10 +1694,10 @@ end
16911694
@test isa(0o1111111111111111111111,UInt64)
16921695
@test isa(0o111111111111111111111111111111111111111111,UInt128)
16931696
@test isa(0o1111111111111111111111111111111111111111111,UInt128)
1694-
@test isa(0o11111111111111111111111111111111111111111111,BigInt)
1695-
@test 0o4000000000000000000000000000000000000000000 ==
1696-
340282366920938463463374607431768211456
1697-
1697+
#@test isa(0o11111111111111111111111111111111111111111111,BigInt)
1698+
@test_throws ParseError parse("0o11111111111111111111111111111111111111111111")
1699+
#@test 0o4000000000000000000000000000000000000000000 ==
1700+
# 340282366920938463463374607431768211456
16981701
# hexadecimal literals
16991702

17001703
@test isa(0x00,UInt8)
@@ -1706,7 +1709,8 @@ end
17061709
@test isa(0x0000000000000000,UInt64)
17071710
@test isa(0x00000000000000000,UInt128)
17081711
@test isa(0x00000000000000000000000000000000,UInt128)
1709-
@test isa(0x000000000000000000000000000000000,BigInt)
1712+
#@test isa(0x000000000000000000000000000000000,BigInt)
1713+
@test_throws ParseError parse("0x000000000000000000000000000000000")
17101714
@test isa(0x11,UInt8)
17111715
@test isa(0x111,UInt16)
17121716
@test isa(0x1111,UInt16)
@@ -1716,7 +1720,8 @@ end
17161720
@test isa(0x1111111111111111,UInt64)
17171721
@test isa(0x11111111111111111,UInt128)
17181722
@test isa(0x11111111111111111111111111111111,UInt128)
1719-
@test isa(0x111111111111111111111111111111111,BigInt)
1723+
#@test isa(0x111111111111111111111111111111111,BigInt)
1724+
@test_throws ParseError parse("0x111111111111111111111111111111111")
17201725

17211726
# "-" is not part of unsigned literals
17221727
@test -0x10 == -(0x10)
@@ -1729,17 +1734,18 @@ end
17291734
@test -0o0000000000000000000001 == -(0o0000000000000000000001)
17301735
@test -0b00000000000000000000000000000000000000000000000000000000000000001 ==
17311736
-(0b00000000000000000000000000000000000000000000000000000000000000001)
1732-
@test -0x000000000000000000000000000000001 == -(0x000000000000000000000000000000001)
1733-
@test -0o0000000000000000000000000000000000000000001 ==
1734-
-(0o0000000000000000000000000000000000000000001)
1735-
@test -0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 ==
1736-
-(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
1737+
#@test -0x000000000000000000000000000000001 == -(0x000000000000000000000000000000001)
1738+
#@test -0o0000000000000000000000000000000000000000001 ==
1739+
# -(0o0000000000000000000000000000000000000000001)
1740+
#@test -0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 ==
1741+
# -(0b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001)
17371742

17381743
@test isa(-0x00,UInt8)
17391744
@test isa(-0x0000000000000000,UInt64)
17401745
@test isa(-0x00000000000000000,UInt128)
17411746
@test isa(-0x00000000000000000000000000000000,UInt128)
1742-
@test isa(-0x000000000000000000000000000000000,BigInt)
1747+
#@test isa(-0x000000000000000000000000000000000,BigInt)
1748+
@test_throws ParseError parse("-0x000000000000000000000000000000000")
17431749

17441750
# Float32 literals
17451751
@test isa(1f0,Float32)

0 commit comments

Comments
 (0)