Repository navigation
parser: apply the MinValue rule only to a literal right after a minus - #58
Merged
Merged
Conversation
A minus before the literals 2147483648 and 9223372036854775808 gives int.MinValue and long.MinValue, as in C#. The check looked at the value of the operand, so it also applied to a literal in parentheses or with the U suffix: - -(2147483648) and -2147483648u were int instead of long, so -(2147483648) - 1 overflowed to 2147483647; - -(9223372036854775808) and -9223372036854775808ul gave long.MinValue, though C# rejects them. Check the literal itself. The number parser now records whether the literal has the U suffix.
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.
A minus before 2147483648 or 9223372036854775808 gives
int.MinValueorlong.MinValue, as in C#. The check looked at the value, not at the syntax, so it also applied to a literal in parentheses or with theUsuffix:-(2147483648)and-2147483648uwereintinstead oflong, so-(2147483648) - 1overflowed to2147483647;-(9223372036854775808)and-9223372036854775808ulgavelong.MinValue, though C# rejects them.The rule now applies only to a literal right after the minus, without the
Usuffix. Expressions from the second case are now errors, as in C#.