Parse the most negative int#2543
Merged
Merged
Conversation
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...
8f60c83 to
be6114f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
-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