Skip to content

Make the calculate_sum sample add its arguments instead of returning "a + b" [patch] - #471

Merged
matt-edmondson merged 2 commits into
mainfrom
claude/optimistic-clarke-nig0o9-coder-470
Nov 11, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
claude/optimistic-clarke-nig0o9-coder-470

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #470

What was wrong

The calculate_sum sample in Coder.Cli, the README and docs/design.md built its return value from AstLeafNode<string>("a + b"). Every generator writes a string leaf as a string literal, so the function returned the text "a + b". Its C#, C++, Rust and Go output failed to compile, and the README's own Python output showed return "a + b".

Change

  • Coder.Cli/SampleCLI.cs, README.md and docs/design.md now build the body as new BinaryExpression(new VariableReference("a"), BinaryOperator.Add, new VariableReference("b")).
  • I regenerated the README's YAML and Python output blocks from the CLI. The Python output now reads return (a + b). The debug parameter name the README uses is kept.
  • CoderCLI.CreateSampleFunction is now public and documented, so the test can build the same sample the CLI prints.
  • Coder.Test now references Coder.Cli.

Tests

  • New Coder.Test/Cli/SampleFunctionTests.cs. It generates the sample in all seven languages, both before and after a YAML round-trip, and checks that each output contains a + b and no "a + b" string literal. It also checks the exact Python signature and return (a + b).
  • With the old AstLeafNode<string> body put back, both tests fail. With the fix, both pass.
  • Full suite: 1666 passed, 0 failed.

The issue suggests a C# compile check as optional ("ideally"). I didn't add one: the text checks already catch the string literal in every target.


Generated by Claude Code

…"a + b" [patch]

The sample in Coder.Cli, the README and docs/design.md built its return value
from an AstLeafNode<string>, which every generator writes as a string literal,
so the function returned the text "a + b" and its C#/C++/Rust/Go output failed
to compile. Build it from a BinaryExpression of two VariableReferences, and
regenerate the README's YAML and Python output from the CLI.

Coder.Test now references Coder.Cli, and SampleFunctionTests generates the
sample in all seven languages, before and after a YAML round-trip, and checks
it adds its arguments and never returns a string literal.

Fixes #470

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4usw8rudxJevraxAd
Comment thread Coder.Test/Cli/SampleFunctionTests.cs Resolved
docs/design.md takes main's unquoted operator: Add, the same value this
branch wrote quoted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW5MLAZoAbekPms
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 0ca6a14 into main Nov 11, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the claude/optimistic-clarke-nig0o9-coder-470 branch November 11, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The flagship calculate_sum sample returns the string "a + b" from an int function, so its generated C#/C++/Rust/Go fails to compile

2 participants