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 output fails to compile (E0594) when a body assigns to a parameter's field or to self.x in an operator, because mut is not added #99
PR #93 declares a Rust parameter mut when the body reassigns it, but two cases were left out.
Coder/Languages/RustGenerator.cs:1002: ReassignedParameters only matches AssignmentStatement { Target: VariableReference target } whose name is exactly a parameter's name. Member access is written as a dotted VariableReference("p.x"), the repo's own convention (CompiledExemplar.cs:154). So p.x = … / p.x += … never matches, and p stays immutable.
RustGenerator.cs:688-695: operator impls write self / rhs directly and never consult the reassignment set at all.
Failure scenario
A free function shifted(p: Point) -> Point { p.x += 1; return p; } generates:
pubfnshifted(p:Point) -> Point{ … }
rustc rejects it: error[E0594]: cannot assign to 'p.x', as 'p' is not declared as mutable.
An operator + (rhs: Point) whose body is self.x += rhs.x; return self; generates:
fnadd(self,rhs:Point) -> Point{ … }
rustc rejects it: error[E0594]: cannot assign to 'self.x', as 'self' is not declared as mutable.
Expected: mut p: Point and fn add(mut self, rhs: Point).
I reproduced both by running the built ktsu.Coder.dll and compiling the output with rustc.
Suggested fix / acceptance criteria
In ReassignedParameters, match on the root of a dotted target (the text before the first .).
In the operator path, run the same scan. Treat self as a candidate for the by-value (self, not &self) operator traits, and write mut on every parameter it finds.
Add both cases to RustGeneratedSourceCompilesTests.
Priority: Medium. The generated Rust fails to compile (E0594) with a clear error. It covers common patterns (mutating a by-value param's field, self.x += in an operator), but nothing miscompiles silently.
Area / suggested assignee: Rust generator, RustGenerator.cs (ReassignedParameters and the operator impl path). Owner: @matt-edmondson
Next step: match the root of dotted assignment targets, run the same scan for operator self/rhs, and add both cases to RustGeneratedSourceCompilesTests.
Activity
matt-edmondson commentedon Sep 27, 2026
Triage
self.x +=in an operator), but nothing miscompiles silently.RustGenerator.cs(ReassignedParametersand the operator impl path). Owner: @matt-edmondsonRustGenerator.csbut not these methods, so a conflict is unlikely.self/rhs, and add both cases toRustGeneratedSourceCompilesTests.Generated by Claude Code