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
The flagship calculate_sum sample returns the string "a + b" from an int function, so its generated C#/C++/Rust/Go fails to compile #470
The sample function that Coder.Cli runs by default, and that the README and docs/design.md show as the canonical usage example, builds its body as:
// Coder.Cli/SampleCLI.cs:115, README.md:264, docs/design.md usage example (~line 211)function.Body.Add(newReturnStatement(newAstLeafNode<string>("a + b")));
LanguageGeneratorBase.TryGenerateCommonNode writes an AstLeafNode<string> as an escaped string literal (Coder/Languages/LanguageGeneratorBase.cs, the case AstLeafNode<string> strLeaf: branch → code.Write($"\"{EscapeString(...)}\"")). So calculate_sum(int a, int b) -> int returns the text "a + b" instead of adding its arguments.
In C# this generates int calculate_sum(...) { return "a + b"; }, which fails with CS0029. C++, Rust and Go reject it the same way.
In Python and JS it runs but returns a string, not the sum.
This is the first example a new user copies, and the one Coder.Cli prints by default, so the main demo of a "generate correct code in N languages" library produces code that doesn't compile.
Suggested fix
Build the body from the expression AST that already exists:
Coder.Cli/SampleCLI.cs, README.md and docs/design.md build the sample body with BinaryExpression, not AstLeafNode<string>
The README's YAML and generated-output blocks are regenerated, and the Python output reads return a + b
A test generates the sample function and asserts the output contains a + b with no quotes (and, ideally, that the C# output compiles, as the existing compile tests do)
Related but separate: #116 (the CLI only prints a hard-coded demo). This issue is about the demo's own output being wrong.
Priority: Medium. The library's generators are fine. The problem is the canonical sample: in the CLI default, the README and docs/design.md, it builds its return value from an AstLeafNode<string>. So the first example a user copies generates C#/C++/Rust/Go that doesn't compile, and Python/JS code that returns "a + b". That makes the project look broken, but the fix is small and nothing downstream depends on it.
Area / suggested assignee: samples and docs: Coder.Cli/SampleCLI.cs, README.md, docs/design.md, plus a generation test. Owner: @matt-edmondson
Next step: replace the leaf with new BinaryExpression(new VariableReference("a"), BinaryOperator.Add, new VariableReference("b")) in all three places. Regenerate the README's YAML and output blocks. Add a test that the sample emits an unquoted a + b, and ideally one that the C# output compiles.
Activity
matt-edmondson commentedon Nov 8, 2026
Triage
docs/design.md, it builds its return value from anAstLeafNode<string>. So the first example a user copies generates C#/C++/Rust/Go that doesn't compile, and Python/JS code that returns"a + b". That makes the project look broken, but the fix is small and nothing downstream depends on it.Coder.Cli/SampleCLI.cs,README.md,docs/design.md, plus a generation test. Owner: @matt-edmondsonDefaultValue = "False"generates C#/C++/JS that fails to compile or throws #182 (READMEDefaultValue = "False"pasted verbatim) was the same kind of README-sample bug. No open Coder PR covers it (open: Resolve .h and .hpp to the C-family generator that writes them [patch] #464, Escape a C# identifier named field, which C# 14 binds inside an accessor [patch] #465, Type a property read as the property's declared type [patch] #468, Write virtual only where C++ and C# accept it [patch] #469).new BinaryExpression(new VariableReference("a"), BinaryOperator.Add, new VariableReference("b"))in all three places. Regenerate the README's YAML and output blocks. Add a test that the sample emits an unquoteda + b, and ideally one that the C# output compiles.Generated by Claude Code