Skip to content

parser: apply the MinValue rule only to a literal right after a minus - #58

Merged
rameel merged 1 commit into
mainfrom
parser/negated-minvalue-literals
Nov 23, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/negated-minvalue-literals

Conversation

@rameel

@rameel rameel commented Nov 23, 2026

Copy link
Copy Markdown
Owner

A minus before 2147483648 or 9223372036854775808 gives int.MinValue or long.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 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.

The rule now applies only to a literal right after the minus, without the U suffix. Expressions from the second case are now errors, as in C#.

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.
@rameel
rameel merged commit b5bd452 into main Nov 23, 2026
1 check passed
@rameel
rameel deleted the parser/negated-minvalue-literals branch November 23, 2026 10:45
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.

1 participant