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
Constructing a type with a declared constructor skips that constructor in C, Go and Rust (C silently builds the wrong value) #297
A ConstructionExpression with positional arguments becomes a call to the type's constructor in C++, C#, Python and JavaScript. C, Go and Rust each generate a constructor (Circle_create, NewCircle, Circle::new), but the call site never uses it:
Go (GoGenerator.cs#L1929-L1952): with one argument it writes the type conversion Circle(5); with more it writes a positional composite literal.
Rust (RustGenerator.cs#L1794-L1827): writes Circle(5), a tuple-struct constructor. The generator only emits named-field structs, so this never compiles for a declared type.
C (CGenerator.cs#L841-L842): writes the compound literal (Circle){ 5 }. It compiles, but it fills the fields in order and never runs the constructor's initialisers.
Reproduction
Circle has two fields, radius and diameter, and one constructor, Circle(int r) : radius(r), diameter(r * 2). The entry point:
cannot convert 5 (untyped int constant) to type Circle
Rust
Circle(5), although Circle::new exists
E0423: expected function, tuple struct or tuple variant, found struct Circle
Why it matters
Calling a constructor is the main reason a type declares one. In Go and Rust the output can't compile at all. In C it compiles but silently builds a different value from the other targets.
Suggested fix / acceptance criteria
Handle a positional ConstructionExpression (no MemberInitialiser arguments) that names a type declared in the generation root, where that type declares a constructor with a matching parameter count. Generate a call to that constructor:
C: Circle_create(5)
Go: NewCircle(5), using the generator's existing New<Type> naming
Rust: Circle::new(5). Rust's BuiltType(...) already finds the declaration.
Keep today's literal or conversion forms for types that aren't declared in the tree, or that have no matching constructor.
Add a compile-and-run test in C, Go and Rust where the constructor computes a field from its argument, and assert the same result as C++ (10).
Related: #68 (closed) covered multi-argument Go construction only.
Priority: High. Go and Rust can't compile any construction of a declared type through its constructor. C compiles but silently builds a different value: diameter is 0 instead of 10, because Circle_create is never called. Silent wrong output is worse than a build failure.
Area / suggested assignee: construction lowering in CGenerator (around L841), GoGenerator (L1929-L1952) and RustGenerator (L1794-L1827), plus the C/Go/Rust GeneratedSourceCompilesTests. Owner: @matt-edmondson
Next step: when a positional ConstructionExpression names a type declared in the generation root that has a constructor with a matching parameter count, emit Circle_create(5), NewCircle(5) or Circle::new(5). Keep today's forms otherwise. Add compile-and-run tests in C, Go and Rust that expect 10.
Activity
matt-edmondson commentedon Oct 19, 2026
Triage
diameteris 0 instead of 10, becauseCircle_createis never called. Silent wrong output is worse than a build failure.CGenerator(around L841),GoGenerator(L1929-L1952) andRustGenerator(L1794-L1827), plus the C/Go/RustGeneratedSourceCompilesTests. Owner: @matt-edmondsonConstructionExpressionnames a type declared in the generation root that has a constructor with a matching parameter count, emitCircle_create(5),NewCircle(5)orCircle::new(5). Keep today's forms otherwise. Add compile-and-run tests in C, Go and Rust that expect 10.Generated by Claude Code