Write a positional construction as a Go composite literal (closes #68) [patch] - #69
Merged
Merged
Conversation
… [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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #68.
What was wrong
GoGenerator.GenerateConstructionExpressionparted its three shapes on whether any argument was aMemberInitialiser. That conflates the two things a type followed by values can be in Go:int64(n)— which takes exactly one operand, andPoint{1, 2}— which lists a struct's fields in declaration order.So a
ConstructionExpressionwith a type and two plain arguments came out asWrapper(1, 2), which Go rejects withtoo 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 stillPoint{X: 1}, one with no type at all is still the bare list the declaration around it types, andint64(n)is untouched.Tests
Both are new, and both fail on
main:GoGeneratorTests.Construction_IsAConversionOnlyWhereItTakesOneValuepins all four shapes in one place. Without the fix:Assert.AreEqual("Wrapper{1, 2}", …)— gotWrapper(1, 2).GoGeneratedSourceCompilesTestsgrows aCornerfield built positionally, used by the driver. This is the shape the exemplar had no case for — the table lists its members by name and thestatic_assertequivalent 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 andgofmtchecks ran rather than reporting inconclusive).🤖 Generated with Claude Code
https://claude.ai/code/session_013HjQ6mUh5eNFYPYWU3GpD2
Generated by Claude Code