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 silently drops the value of a constant (non-static) field, and of every instance-field initializer: the struct is zero-valued #111
GoGenerator decides where a field goes from IsStatic alone:
Coder/Languages/GoGenerator.cs ~line 580 writes package-level storage for field.IsStatic.
~line 732 makes a struct member of !field.IsStatic.
A FieldDeclaration with IsConstant = true and IsStatic = false therefore becomes an ordinary struct field, and its InitialValue is dropped with no note. Every other target treats a constant as belonging to the type:
pub const Ratio: f64 = 0.5; via IsStatic || IsConstant
C
double Ratio; // constant, 0.5
Go
Ratio float64 (value lost)
Go also drops ordinary instance-field initializers without a note. Hits = 5 becomes Hits int, and the generated constructor returns Cfg{}. C at least writes // defaults to 5.
Under go run, printing NewCfg()'s fields gives 0 0. The C# and C++ outputs give 0.5 and 5.
Suggested fix
Change both predicates to field.IsStatic || field.IsConstant, matching RustGenerator.IsAssociatedField. Ratio then becomes a package-level const CfgRatio float64 = 0.5, the same path static fields already take.
For instance fields with an InitialValue, set them in the generated constructor's composite literal (Cfg{Hits: 5}), or at least emit a note as the C generator does.
Acceptance criteria
Constant fields keep their value in Go output.
A struct with initialized instance fields constructed via NewX() reports the initial values, or the output carries an explicit note that they are not applied.
Priority: High. The Go output compiles and runs but silently gives zero values where the model says 0.5 and 5. No error or note warns the caller, so wrong behaviour ships unnoticed.
Area / suggested owner:GoGenerator field placement (~580 / ~732) and constructor composite-literal generation
Notes: The constant half is a two-predicate change that reuses the existing static-field path. The instance-initializer half (Cfg{Hits: 5}) is larger and could ship separately, with a C-style note as the interim fallback.
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
0.5and5. No error or note warns the caller, so wrong behaviour ships unnoticed.GoGeneratorfield placement (~580 / ~732) and constructor composite-literal generationIsStatic || IsConstant), and a companion to JavaScript ignores FieldDeclaration.IsStatic/IsConstant: static class fields become per-instance, and a file-scope field is an undeclared assignment that throws in an ES module #104 (JavaScript ignoringIsStatic/IsConstant). No open PR references it.Cfg{Hits: 5}) is larger and could ship separately, with a C-style note as the interim fallback.Generated by Claude Code