What's wrong
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:
| Target |
Output for Ratio (constant, 0.5) |
| C# |
public static readonly double Ratio = 0.5d; |
| C++ |
static constexpr double Ratio = 0.5; |
| Rust (fixed in #81) |
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.
Repro
var cls = new ClassDeclaration("Cfg") { Kind = TypeDeclarationKind.Struct };
cls.Members.Add(new FieldDeclaration("Ratio", new TypeReference("double")) { IsConstant = true, InitialValue = Literal.DecimalValue(0.5) });
cls.Members.Add(new FieldDeclaration("Hits", new TypeReference("int")) { InitialValue = Literal.Number(5) });
cls.Members.Add(new FunctionDeclaration("Cfg") { Kind = FunctionKind.Constructor });
Console.WriteLine(new GoGenerator().Generate(cls));
Actual:
type Cfg struct {
Ratio float64
Hits int
}
func NewCfg() Cfg { return Cfg{} }
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.
What's wrong
GoGeneratordecides where a field goes fromIsStaticalone:Coder/Languages/GoGenerator.cs~line 580 writes package-level storage forfield.IsStatic.!field.IsStatic.A
FieldDeclarationwithIsConstant = trueandIsStatic = falsetherefore becomes an ordinary struct field, and itsInitialValueis dropped with no note. Every other target treats a constant as belonging to the type:Ratio(constant,0.5)public static readonly double Ratio = 0.5d;static constexpr double Ratio = 0.5;pub const Ratio: f64 = 0.5;viaIsStatic || IsConstantdouble Ratio; // constant, 0.5Ratio float64(value lost)Go also drops ordinary instance-field initializers without a note.
Hits = 5becomesHits int, and the generated constructor returnsCfg{}. C at least writes// defaults to 5.Repro
Actual:
Under
go run, printingNewCfg()'s fields gives0 0. The C# and C++ outputs give0.5and5.Suggested fix
field.IsStatic || field.IsConstant, matchingRustGenerator.IsAssociatedField.Ratiothen becomes a package-levelconst CfgRatio float64 = 0.5, the same path static fields already take.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
NewX()reports the initial values, or the output carries an explicit note that they are not applied.