Skip to content

Parse the most negative int#2543

Merged
plajjan merged 7 commits into
mainfrom
parse-neg-int
Dec 4, 2025
Merged

Parse the most negative int#2543
plajjan merged 7 commits into
mainfrom
parse-neg-int

Conversation

@plajjan

@plajjan plajjan commented Nov 30, 2025

Copy link
Copy Markdown
Contributor

-9223372036854775808 is the most negative values of our int (i64). The standard lexer produces two tokens: - 9223372036854775808, which means this is constructed as an int64 type with the value 9223372036854775808 prefixed by the unary operator -. However, 9223372036854775808 is too large to be stored in a i64, so it fails.

We now parse negative integers into actual negative integers by combining the UMinus with the int value in the parser (after the lexer). Accordingly, CodeGen must now be able to produce negative bigint literals, which it does using a string C literal. Also adjusted type inference for large negative integers which now become bigint rather than int.

Added a new ints tests using codegen golden output to show the generated code.

Fixes #2545

Kristian Larsson added 7 commits December 3, 2025 22:36
-9223372036854775808 is the most negative values of our int (i64). The
standard lexer produces two tokens: - 9223372036854775808, which means
this is constructed as an int64 type with the value 9223372036854775808
prefixed by the unary operator -. However, 9223372036854775808 is too
large to be stored in a i64, so it fails.

We now parse negative integers into actual negative integers by
combining the UMinus with the int value in the parser (after the lexer).

Added a few tests and some helpers to parse just Stmt or Expr, this seems to
work.
We expect this to be a bigint...
@plajjan plajjan force-pushed the parse-neg-int branch 2 times, most recently from 8f60c83 to be6114f Compare December 4, 2025 06:42
@plajjan plajjan enabled auto-merge December 4, 2025 06:49
@plajjan plajjan merged commit 15fc5b2 into main Dec 4, 2025
133 of 136 checks passed
@plajjan plajjan deleted the parse-neg-int branch December 4, 2025 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some bigint literals aren't handled correctly

1 participant