Add typed numeric literal suffixes#20
Merged
Merged
Conversation
wtholliday
approved these changes
Jun 6, 2026
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.
This PR introduces typed numeric suffixes for integer and floating-point literals.
Supported suffixes:
i32,u32u, normalized asu32f32,f64Examples:
Suffixes force an exact literal type. Unsuffixed integer and float literal behavior is otherwise unchanged.
Design Notes
The AST now represents numeric literals as:
This removes the legacy unsigned literal AST variant while keeping literal handling simple. The
usuffix is accepted as an alias foru32and intentionally normalizes tou32; the AST does not preserve the source spelling.Integer-valued float literals such as
1f64are intentionally not accepted. Float suffixes require a real literal spelling such as1.0f64.Signed minimum values are handled as a literal-position rule: a leading unary
-is considered during signed suffix range validation. This allows-2147483648i32, while still rejecting2147483648i32.Suffixes remain expression-literal syntax only. Suffixed integers are rejected for tuple field indices, array type sizes, and integer
constdeclarations, preserving the current const behavior for a future dedicated const-system PR.Why
i8andu8Are OmittedThis PR intentionally limits suffixes to numeric types that already participate in the language's arithmetic surface.
i8is source-reachable today, but it is mostly a byte/storage/interoperability type. It is used for characters, strings, casts, and byte-sized storage, but it does not currently participate in ordinary arithmetic, relational comparisons, or unary negation. Adding ani8suffix would make1i8 + 2i8look like an expected use case even though the checker rejects that operation today.u8is even less settled. The type exists internally, but it is not exposed as a source primitive onmain. Makingu8literals source-reachable also exposed backend consistency questions around byte loads and casts, especially in the stack backend.For those reasons, byte-sized integer suffixes are deferred. A future PR should decide the intended byte integer model explicitly: whether
i8/u8are full arithmetic numeric types or storage/cast-oriented byte types, and then align parsing, type checking, casts, memory loads, and backend behavior around that decision.Implementation
Suffixes now flow through:
Validation
This adds coverage for:
i32andu32boundary checksf32/f64type mismatch checks1i64,1i8,1u8, integer-valued float suffixes such as1f64, and float literals with integer suffixes such as1.0uVerified with:
cargo test --workspace