What's wrong
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:
pub fn shifted(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:
fn add(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.
What's wrong
PR #93 declares a Rust parameter
mutwhen the body reassigns it, but two cases were left out.Coder/Languages/RustGenerator.cs:1002:ReassignedParametersonly matchesAssignmentStatement { Target: VariableReference target }whose name is exactly a parameter's name. Member access is written as a dottedVariableReference("p.x"), the repo's own convention (CompiledExemplar.cs:154). Sop.x = …/p.x += …never matches, andpstays immutable.RustGenerator.cs:688-695: operator impls writeself/rhsdirectly and never consult the reassignment set at all.Failure scenario
A free function
shifted(p: Point) -> Point { p.x += 1; return p; }generates:rustcrejects it:error[E0594]: cannot assign to 'p.x', as 'p' is not declared as mutable.An operator
+(rhs: Point) whose body isself.x += rhs.x; return self;generates:rustcrejects it:error[E0594]: cannot assign to 'self.x', as 'self' is not declared as mutable.Expected:
mut p: Pointandfn add(mut self, rhs: Point).I reproduced both by running the built
ktsu.Coder.dlland compiling the output withrustc.Suggested fix / acceptance criteria
ReassignedParameters, match on the root of a dotted target (the text before the first.).selfas a candidate for the by-value (self, not&self) operator traits, and writemuton every parameter it finds.RustGeneratedSourceCompilesTests.