Repository navigation
Follow a Go local with _ = name so an unread one compiles [patch] - #275
Merged
Merged
Conversation
Go refuses a local nothing reads ("declared and not used"), and a body is
free to declare one it never reads or only assigns to, which the other six
targets accept. GoGenerator now writes `_ = name` after every local, the
same as the entry point's `_ = args`. A package-level declaration gets
none, since Go allows an unread one there and refuses a statement outside
a function; a body depth counter tells the two apart.
Fixes #272
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CFV1ukfTLyVhjxAWRuEzGD
|
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 #272
What changed
Go refuses a local that nothing reads ("declared and not used"). The other six targets accept a body that declares a local and never reads it, or only assigns to it, but the Go output for that body didn't compile.
GoGenerator.GenerateVariableDeclarationnow writes_ = nameafter every local. This follows the precedent of the entry point's_ = args.WriteBodytells the two apart.Tests
GoGeneratedSourceCompilesTests.UnreadLocals_Compilebuilds, withgo build, a function with an unread typed local, one with an inferred local that is only assigned to plus a zero-valued local, and one whose local is read. It also checks the output againstgofmt -l. With the generator change reverted, it fails withdeclared and not used: t,wandz.Generated by Claude Code