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
Go: narrower numbers in struct literals, constructor initialisers and typed list elements aren't converted (Acc{total: a} with int → int64), so the output doesn't compile #408
f2f5694 (#238) added WriteWidened for Rust and Go. It covers operands, typed initialisers, assignments, returns and call arguments. Rust also widens the values in a struct literal: it tracks literalType and looks up each field's type with InstanceFieldType (RustGenerator.cs L2320-L2333, L2396). Go has no equivalent:
) writes member initialiser values and list elements straight through WriteElementList, without GenerateWidenedTo.
WriteConstructorBody (GoGenerator.cs L1289-L1310) builds the constructor's return value through the same path, so constructor initialisers are affected too.
Repro
struct Acc { long total; }, with an int a parameter in each case:
Acc build(int a) { return Acc{ total = a }; } → Go return Acc{total: a} → cannot use a (variable of type int) as int64 value in struct literal
Constructor Acc(int a) : total(a) → func NewAcc(a int) Acc { return Acc{total: a} } fails the same way.
long[] xs = { a }; → var xs []int64 = []int64{a} fails the same way.
Rust writes Acc { total: (a as i64) } for the same AST.
Acceptance criteria
In a Go composite literal, each member initialiser's value is widened to its declared field type when the document declares the type, as Rust already does.
Each element of a typed slice or array literal is widened to the element type.
A case is added to GoGeneratedSourceCompilesTests.
Priority: Medium. Go output fails to compile when a narrower number goes into a struct literal, a constructor initialiser or a typed list. Rust already handles all three. The failure is loud, and the fix can follow the Rust pattern (literalType + InstanceFieldType).
Area:GoGenerator.GenerateConstructionExpression / WriteElementList and WriteConstructorBody, which should route values through GenerateWidenedTo. Test goes in GoGeneratedSourceCompilesTests.
Activity
matt-edmondson commentedon Oct 31, 2026
Triage
literalType+InstanceFieldType).GoGenerator.GenerateConstructionExpression/WriteElementListandWriteConstructorBody, which should route values throughGenerateWidenedTo. Test goes inGoGeneratedSourceCompilesTests.x * 2on an f64,a + bon i64/i32,long f(int b) { return b; }#238 (closed) addedWriteWidened, and this is a gap it left. A shift is typed as the wider of its two operands, so int << long fails to compile in Go and Rust and JavaScript computes chained shifts in 64 bits #362 (open) is a separate Go/Rust widening defect, with shifts typed as the wider operand. Rust writes a typeless braced list as an array where a Vec is expected (let xs: Vec<i32> = [1, 2]; E0308), and Go writes a barereturn {1}#409 is a nearby Go typed-literal issue.Generated by Claude Code