Skip to content

parser: reject real type suffixes after hexadecimal and binary literals - #52

Merged
rameel merged 1 commit into
mainfrom
parser/hex-binary-real-suffixes
Nov 20, 2026
Merged

rameel merged 1 commit into
mainfrom
parser/hex-binary-real-suffixes

Conversation

@rameel

@rameel rameel commented Nov 20, 2026

Copy link
Copy Markdown
Owner

A hexadecimal or binary literal accepted the real type suffixes d, f, and m, which C# allows only after decimal digits:

Literal Before After
0b101d 5 (Double) (1:6) Expected '(', '[', '.', ':>', ...
0b1f 1 (Single) (1:4) Expected ...
0b1m, 0x10m 1, 16 (Decimal) (1:4) Expected ..., (1:5) Expected ...

C# rejects all of them (CS1003). In a hexadecimal literal, d and f are digits, so 0x1d and 0x1F stay the integers 29 and 31.

Since #51, decimal digits followed by d, f, or m are read as real literals, so only hexadecimal and binary literals reached the suffix handling in AdjustNumericType. This PR removes it; 1d, 1f, and 1m are not affected.

Expressions that relied on these suffixes, such as 0x10m, no longer parse.

A hexadecimal or binary literal accepted the real type suffixes that
C# allows only after decimal digits: 0b101d was the double 5, 0b1f a
float, and 0b1m and 0x10m decimals. In a hexadecimal literal, d and f
are digits, so only m was affected there.

Decimal digits followed by d, f, or m are now read as real literals,
so only hexadecimal and binary literals reached the suffix handling in
AdjustNumericType. Remove it, so that the letter is left after the
literal and reported as a syntax error at its position, as in C#.
@rameel
rameel merged commit efedd75 into main Nov 20, 2026
1 check passed
@rameel
rameel deleted the parser/hex-binary-real-suffixes branch November 21, 2026 11:55
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