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
s += name on strings fails to compile in Rust (E0308) and C (invalid operands): the #240 fix only covers a + b, not += #363
#240 / PR #323 made string Add work in Rust (format!, RustGenerator.GenerateBinary) and added an explanatory note in C (CGenerator.GenerateBinary). Both hooks only see a BinaryExpression.
An AssignmentStatement with AssignmentOperator.AddAssign on a string target goes through StandardLanguageGenerator.GenerateAssignmentStatement (Coder/Languages/StandardLanguageGenerator.cs, around lines 1929-1956) and comes out as a plain +=.
The compound form has needed its own handling before. Floating %= is special-cased in that same method, and #183 was the /= follow-up to #114.
The input is string greet(string name) { string s = "Hello, "; s += name; return s; }, with the assignment built as new AssignmentStatement(new VariableReference("s"), new VariableReference("name"), AssignmentOperator.AddAssign):
Target
Generated
Compiler
Rust
let mut s: String = String::from("Hello, "); / s += name;
rustc E0308: expected &str, found String
C
const char* s = "Hello, "; / s += name;
gcc -std=c11: invalid operands to binary + (have 'const char *' and 'const char *'), and no note
Go and C++ (std::string) compile as they are.
Suggested fix / acceptance criteria
Rust: when the target's static type is an owned String and the value is a String, write s += &name (or s.push_str(&name)). Keep s += "lit" as it is.
C: put the same "C has no string concatenation" note in front of a string += that GenerateBinary puts in front of a string +.
Priority: Medium. Generated Rust fails to compile, and generated C fails with no explanatory note, for a common pattern (s += name on strings). Other targets are fine, and the fix extends an existing hook to the compound form.
Area: Code generation for compound assignment: StandardLanguageGenerator.GenerateAssignmentStatement (around lines 1929-1956), plus the Rust and C string-concatenation hooks (RustGenerator.GenerateBinary, CGenerator.GenerateBinary).
Activity
matt-edmondson commentedon Oct 30, 2026
Triage
s += nameon strings). Other targets are fine, and the fix extends an existing hook to the compound form.StandardLanguageGenerator.GenerateAssignmentStatement(around lines 1929-1956), plus the Rust and C string-concatenation hooks (RustGenerator.GenerateBinary,CGenerator.GenerateBinary).Addon string operands) fails to compile in C and Rust:"Hello, " + name(C: invalid operands; Rust: E0369/E0308) #240 / PR Write string joins as format! in Rust and note them in C #323, which handled thea + bform. The same pattern of a compound form needing its own handling came up in Compound/=and%=give different results in Python and JavaScript:a /= 2makes an int 2.5 (not covered by #114) #183 (/=after Integer division and modulo give different results in Python and JavaScript:-7 / 2returns -3 in C/C++/C#/Go/Rust but -3.5 in Python and JS #114). Also related to Adding a number to a string ("count: " + n) raises TypeError in Python, fails to compile in Go, and returns garbage in C++ #350 (string + number) and Rust: main() body has no static-type scope, so string joins and int-to-long widening fail to compile there (E0308/E0277) #338 (string joins inside Rustmain()).+=.Generated by Claude Code