Write a Go type down over the whole declaration, not its first line - #72
Merged
Merged
Conversation
…loses #63) [patch] A type parameter on a ClassDeclaration is written down rather than written, which is the decision CLAUDE.md states. The emission only half kept it: the type was declared without parameters, and then a field, a parameter and a result went on spelling them — `held T` and `Boxed[T]` beside a `Boxed` that takes none. That is `undefined: T` and `Boxed is not a generic type`, neither of which the text shows. The write-down now reaches the whole declaration. While a type's members are written, its parameters are names the file does not hold, so a type spelled for one is spelled `any`, and a mention of the type itself carries no arguments. A type parameter on a function is a real one and reaches none of this. The note above the declaration says what became of them, so the comment and the file under it agree. GoGeneratedSourceCompilesTests grows the case it was missing — a struct with a parameterised field, a static factory answering the type, and a driver using both — so the answer is compiled rather than asserted, which is the only way either error is visible. GoGeneratorTests pins the same shape headlessly, for where no Go toolchain is on the path. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KGA295odwYgzWvncYaLEu3
|
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 #63
What was wrong
CLAUDE.mdstates the decision: a type parameter on aClassDeclarationis written down rather than written, because a method on a generic Go type needs the parameters in three places and spelled two ways. The emission only half kept it — the type was declared without parameters, and then a field, a parameter and a result went on spelling them:Three things disagree in six lines, and
go vetsays so:undefined: T, andLength[T]subscripts a type that takes no parameters. Nothing in the text shows either.What changed
The write-down now reaches the whole declaration rather than its first line, which is the resolution the issue calls the smaller one and the one that matches the stated decision.
GoGeneratorholds the parameters a type was written down over for as long as that type's members are being written. A type spelled for one of those names is spelledany; a mention of the type itself carries no arguments, because a type declared without parameters takes none.func first[T any](values []T) Tis unchanged.The same input now comes out as:
Spelling
SpellType,SpellTypeNameand their callers is now instance work rather than static, since the answer depends on which declaration is being written.Tests
GoGeneratedSourceCompilesTestsgrows the case it was missing, which is the point of the issue's Missing coverage section: a struct with a parameterised field, a static factory answering the type, and a driver in the same package that uses both. This is the only way either error is visible —RustGeneratedSourceCompilesTestshas had the equivalent all along, which is why Rust's answer was right and this one was not.GoGeneratorTestspins the same shape headlessly, so the answer still holds where no Go toolchain is on the path, plus a companion case asserting a function's own parameters stay generic.Verified by reverting
GoGenerator.csalone and re-running: both new checks fail (./exemplar.go:101:7: undefined: T,invalid operation: Boxed[T] (Boxed is not a generic type)), and pass with the change. Full suite: 861 passed, 0 failed, with a real Go 1.24 toolchain on the path. Release build of the solution is clean.CLAUDE.mdis updated so the stated decision includes the half that makes it hold.🤖 Generated with Claude Code
https://claude.ai/code/session_01KGA295odwYgzWvncYaLEu3
Generated by Claude Code