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 and C constructors drop instance-field initialisers: Rust fails with E0063 and C silently starts the field at 0 #193
#111 / #187 made Go's constructors set every instance field that declares an InitialValue and that the constructor does not set itself (Coder/Languages/GoGenerator.cs:1189-1197). The Rust and C generators have the same constructor shape and were not changed:
Rust:RustGenerator.WriteConstructorBody (Coder/Languages/RustGenerator.cs:1062-1082) builds Self { … } from funcDecl.Initialisers only. An initialised instance field the constructor doesn't name is left out of the struct literal, so rustc rejects it with E0063 ("missing field"). With no initialisers at all it writes Self::default(), so the declared default is lost there too.
C:CGenerator.GenerateConstructorBody (Coder/Languages/CGenerator.cs:276-302) writes { .member = … } from funcDecl.Initialisers only, or {0} when there are none, so the field starts at 0 — while the struct member carries the comment // defaults to 5 (CGenerator.cs:680), which says the opposite.
C++, C#, JavaScript, Python and (since #187) Go all honour the default.
Reproduction (verified with rustc and gcc)
ClassDeclaration("Counter") with field count: int = 5, field step: int, and a constructor (int s) with initialiser step = s.
Rust output:
pubfnnew(s:i32) -> Self{Self{step: s }}
→ error[E0063]: missing field 'count' in initializer of 'Counter'.
Mirror GoGenerator: for each initialised instance field a constructor doesn't name, add it to the Rust Self { … } literal and the C designated initialiser, including when the constructor has no initialisers (instead of Self::default() / {0}). StandardLanguageGenerator.InstanceInitialised can supply the list.
Add compile-and-run tests in RustGeneratedSourceCompilesTests and CGeneratedSourceCompilesTests for a type with an initialised field its constructor doesn't set; the field must read back its declared value.
Keep the C struct comment accurate (say the constructor applies the default, or drop it).
Priority: Medium. Rust output fails to compile (E0063) and C output silently starts the field at 0, contradicting its own // defaults to 5 comment. Other targets already honour the default, and Keep Go constant-field values and apply instance-field initialisers #187 gives a direct template to mirror.
Area / suggested assignment: Language generators: RustGenerator.WriteConstructorBody, CGenerator.GenerateConstructorBody, using StandardLanguageGenerator.InstanceInitialised.
Activity
matt-edmondson commentedon Oct 7, 2026
Triage
// defaults to 5comment. Other targets already honour the default, and Keep Go constant-field values and apply instance-field initialisers #187 gives a direct template to mirror.RustGenerator.WriteConstructorBody,CGenerator.GenerateConstructorBody, usingStandardLanguageGenerator.InstanceInitialised.this.x = ;(C#/JS),self.x =(Python) andSelf {}(Rust), none of which compile #178 (empty initialiser emitsSelf {}) and A constructor initialiser naming the base class only reaches the base constructor in C++ and JavaScript; Python, C#, Go, Rust and C treat it as a field #169 (base-class initialiser treated as a field in Rust and C), so watch for conflicts if they are fixed in parallel.Generated by Claude Code