Skip to content

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

Closed

Description

@matt-edmondson

What's wrong

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(new ReturnStatement(new AstLeafNode<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.

The README's own expected output shows this:

def calculate_sum(a: int, b: int, include_debug: bool = False) -> int:
    return "a + b"

Why it matters

  • 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:

function.Body.Add(new ReturnStatement(
    new BinaryExpression(new VariableReference("a"), BinaryOperator.Add, new VariableReference("b"))));

(BinaryExpression constructor: Coder/Ast/BinaryExpression.cs:32.)

Acceptance criteria

  • 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.

Activity

  1. matt-edmondson commented on Nov 8, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions