You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rust output fails to compile ("literal out of range for i32") when an inferred local is initialised with a long literal above i32 range #122
RustGenerator.GenerateVariableDeclaration (Coder/Languages/RustGenerator.cs:1109-1129) leaves the type annotation off when the type is inferred. It then writes the initialiser through LanguageGeneratorBase, which emits a LiteralExpression<long> as bare digits with no suffix (LanguageGeneratorBase.cs:140-141). RustGenerator does not override literal emission.
Rust infers an unconstrained integer literal as i32. A long value outside the i32 range therefore trips the overflowing_literals lint, which is deny-by-default, and compilation fails.
Failure scenario
newFunctionDeclaration("main"){Body={newVariableDeclaration("big",null,Literal.BigNumberValue(5_000_000_000))/* then only printed */},}
The generator emits let mut big = 5000000000;. If nothing later constrains big (for example, it is only printed), rustc 1.94.1 rejects it:
error: literal out of range for `i32`
Both the generator output and the rustc failure were reproduced during review. If a later use pins big to i64, the code compiles, so the failure needs an unconstrained local.
The other targets all keep the value's type:
C# adds the L suffix.
C++ uses auto.
Go uses :=.
Python and JavaScript don't need a width.
LiteralExpression<float> has a similar loss of intent: let x = 0.1; becomes an f64. It compiles, but the declared precision is gone.
Suggested fix
In RustGenerator, emit a long literal with an i64 suffix and a float literal with an f32 suffix (5000000000i64, 0.1f32). This mirrors what CSharpGenerator already does with L/f. Alternatively, write : i64 / : f32 on an inferred declaration whose initialiser is such a literal.
Add the case to RustGeneratedSourceCompilesTests so rustc checks it.
Related
#84 and #99 are also Rust compile failures, but from different causes.
Category: Bug (the Rust generator emits code that fails to compile)
Priority: Medium. The Rust output doesn't compile, but only when an inferred local is initialised with a long literal outside the i32 range and nothing later constrains its type. The float → f64 case compiles but loses the declared precision.
Area / suggested assignment:Coder/Languages/RustGenerator.cs (literal emission), plus RustGeneratedSourceCompilesTests.
Suggested next step: override literal emission in RustGenerator to add the i64 and f32 suffixes, mirroring CSharpGenerator's L/f. Then add the unconstrained-local case to the rustc compile test.
Activity
matt-edmondson commentedon Sep 29, 2026
Triage
longliteral outside thei32range and nothing later constrains its type. Thefloat→f64case compiles but loses the declared precision.Coder/Languages/RustGenerator.cs(literal emission), plusRustGeneratedSourceCompilesTests.str/stringtype, which maps to ownedString#84 and Rust output fails to compile (E0594) when a body assigns to a parameter's field or to self.x in an operator, because mut is not added #99 are other Rust compile failures with different causes. Open PR [patch] Make a string literal an owned String where Rust receives one #120 (for Rust output fails to compile (E0308) wherever a string literal is returned as, or assigned to, astr/stringtype, which maps to ownedString#84) edits the same generator, so expect a small merge overlap.Suggested next step: override literal emission in
RustGeneratorto add thei64andf32suffixes, mirroringCSharpGenerator'sL/f. Then add the unconstrained-local case to the rustc compile test.Generated by Claude Code