Skip to content

Write a positional construction as a Go composite literal (closes #68) [patch] - #69

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/go-positional-construction
Sep 14, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/go-positional-construction

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #68.

What was wrong

GoGenerator.GenerateConstructionExpression parted its three shapes on whether any argument was a MemberInitialiser. That conflates the two things a type followed by values can be in Go:

  • a conversion, int64(n) — which takes exactly one operand, and
  • a positional composite literal, Point{1, 2} — which lists a struct's fields in declaration order.

So a ConstructionExpression with a type and two plain arguments came out as Wrapper(1, 2), which Go rejects with too many arguments in conversion to Wrapper. It is not a longer conversion; there is no such thing.

The change

Coder/Languages/GoGenerator.cs — route to the brace list whenever the argument count is not exactly one, and reserve the parenthesised form for the single operand that genuinely is a conversion. The single-argument loop collapses to one write now that it can only ever run once. The <remarks> says why the count is what parts the two, since the old text explained the shapes but not the boundary.

Nothing else moves: an empty construction is still Point{}, one naming its members is still Point{X: 1}, one with no type at all is still the bare list the declaration around it types, and int64(n) is untouched.

Tests

Both are new, and both fail on main:

  • GoGeneratorTests.Construction_IsAConversionOnlyWhereItTakesOneValue pins all four shapes in one place. Without the fix: Assert.AreEqual("Wrapper{1, 2}", …) — got Wrapper(1, 2).
  • GoGeneratedSourceCompilesTests grows a Corner field built positionally, used by the driver. This is the shape the exemplar had no case for — the table lists its members by name and the static_assert equivalent constructs nothing — so a real toolchain now checks it. Without the fix: ./exemplar.go:89:29: too many arguments in conversion to Point.

Verified by reverting the generator change, rebuilding, and watching both tests fail with exactly those messages, then restoring it.

Full suite: 858 passed, 0 failed (net10.0, with a Go toolchain on the path so the compile and gofmt checks ran rather than reporting inconclusive).

🤖 Generated with Claude Code

https://claude.ai/code/session_013HjQ6mUh5eNFYPYWU3GpD2


Generated by Claude Code

… [patch]

Go's conversion syntax takes exactly one operand, so a ConstructionExpression
with a type and two or more plain arguments came out as Wrapper(1, 2) — which
the compiler rejects with "too many arguments in conversion to Wrapper" rather
than reading as a longer conversion. The branch only asked whether any argument
named a member, conflating a conversion with the other composite literal Go has:
the one listing a struct's fields in declaration order.

Route anything but a single argument to the brace list, and reserve the
parenthesised form for the one-operand case that is actually a conversion.

The exemplar the Go compile test builds now holds a positionally constructed
value, so the shape is checked by a real toolchain rather than only pinned as
text: the table lists its members by name and the assertion constructs nothing,
so this was the one construction nothing compiled.

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 66ec511 into main Sep 14, 2026
13 checks passed
@matt-edmondson
matt-edmondson deleted the claude/go-positional-construction branch September 14, 2026 14:40
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.

GoGenerator emits call-syntax construction for multi-argument positional ConstructionExpression, which doesn't compile

2 participants