diff --git a/example/syntax.wren b/example/syntax.wren index 8e2f5d54..afb313f9 100644 --- a/example/syntax.wren +++ b/example/syntax.wren @@ -130,9 +130,8 @@ class Literals is SyntaxExample { 1.0 -12.34 0x1000000 -// Literals larger than 0x1000000 are only valid in 64 bit builds -// 0xdeadbeef -// 0x1234567890ABCDEF + 0xdeadbeef + 0x1234567890ABCDEF } strings { diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index a1456bab..c2e7bd63 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -712,16 +712,23 @@ static void makeNumber(Parser* parser, bool isHex) { errno = 0; - // We don't check that the entire token is consumed because we've already - // scanned it ourselves and know it's valid. - parser->current.value = NUM_VAL(isHex ? strtol(parser->tokenStart, NULL, 16) - : strtod(parser->tokenStart, NULL)); + if (isHex) + { + parser->current.value = NUM_VAL(strtoll(parser->tokenStart, NULL, 16)); + } + else + { + parser->current.value = NUM_VAL(strtod(parser->tokenStart, NULL)); + } if (errno == ERANGE) { - lexError(parser, "Number literal was too large."); + lexError(parser, "Number literal was too large (%d).", sizeof(long int)); parser->current.value = NUM_VAL(0); } + + // We don't check that the entire token is consumed after calling strtoll() + // or strtod() because we've already scanned it ourselves and know it's valid. makeToken(parser, TOKEN_NUMBER); } diff --git a/test/language/number/hex_literals.wren b/test/language/number/hex_literals.wren index 5a63d96d..1d4ed604 100644 --- a/test/language/number/hex_literals.wren +++ b/test/language/number/hex_literals.wren @@ -5,4 +5,5 @@ System.print(x + 1) // expect: 256 System.print(x == 255) // expect: true System.print(0x09 is Num) // expect: true System.print(x is Num) // expect: true -System.print(-0xFF) // expect: -255 \ No newline at end of file +System.print(-0xFF) // expect: -255 +System.print(0xdeadbeef) // expect: 3735928559