Repository navigation
Escape keyword-named identifiers in the Go generator [patch] - #445
Merged
Merged
Conversation
A field, parameter, local, method, function, package-level variable or designated member named after a Go keyword came out verbatim, so the package failed to parse: a field called type or range, or a parameter called chan or select, was enough. Go now appends an underscore at each declaration, and references and calls go through the same hook so they agree. The predeclared identifiers (nil, true, len, int) are names Go lets any declaration shadow, so they are not escaped. Exported names and names joined to their type's (HolderMake) are never keywords, since every Go keyword is lower case. Part of #106. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3mc54mR7dMPMARSVv
This was referenced Nov 4, 2026
matt-edmondson
pushed a commit
that referenced
this pull request
Nov 7, 2026
Keeps ReservedWordIdentifierTests.cs untouched, so this branch and the Go keyword PR (#445) merge in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3ect9msbMq1zFsRLD
matt-edmondson
added a commit
that referenced
this pull request
Nov 10, 2026
* Escape keyword-named bindings in the JavaScript generator [patch] JavaScript wrote keyword-named parameters, locals, functions, classes and top-level names verbatim, so `total(in, typeof)` or `function return(...)` failed to parse. These bindings now get an underscore (`in_`, `return_`) at the declaration and at every use. Members keep their names. JavaScript reads a keyword after a `.` and as a field, accessor or method name, so `holder.default` and `this.switch()` stay as written. A new `EscapesMemberNames` hook on LanguageGeneratorBase tells EscapeReference to escape only a reference's leading segment, and SpellCallee to leave a call with a receiver alone and to count only free functions. Part of #106. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3ect9msbMq1zFsRLD * Move the JavaScript keyword tests into their own file Keeps ReservedWordIdentifierTests.cs untouched, so this branch and the Go keyword PR (#445) merge in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3ect9msbMq1zFsRLD --------- Co-authored-by: Claude <noreply@anthropic.com>
Keeps both the Go reserved words and main's SharesNameWithGetter and MemberNameKey overrides, which were added at the same spot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3mc54mR7dMPMARSVv
|
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.



Part of #106 (Go target). C is covered separately by #446, and the issue stays open for JavaScript.
What was wrong
The Go generator wrote identifiers named after Go keywords as they were. A struct field called
typeorrange, a parameter calledchanorselect, a local calledgoordefer, a method calledswitch, a function calledfunc, or a package-levelvar mapwas enough to make the package fail to parse:Change
GoGeneratornow declaresReservedWords: the 25 keywords in the Go spec. It uses the baseEscapeIdentifier, which appends_._ = nameline and the conditional-lowering form), and methods and free functions.Holder{type_: 3}) already go throughEscapeReference,SpellCalleeandWriteListElement, so they come out the same as the declarations. One Go-only call path, a call whose receiver is a composite literal, wrotecall.Calleedirectly; it now goes throughSpellCalleetoo.nil,true,len,int) are not keywords, and Go lets any declaration shadow them, so they are not escaped.HolderMake), can never be keywords, because every Go keyword is lower case.Tests
Go_KeywordNamesCompileAndResolvegenerates a package full of keyword-named members. It runs it withgo runagainst a driver that reads each escaped name back, then checks thatgofmt -lreports nothing. It failed before this change with the syntax errors above.Go_ReferenceKeepsTheReceiverAndPredeclaredNamesAndEscapesTheMemberchecks thatself.chanbecomesself.chan_whileselfandtruestay as written.dotnet test --project Coder.Test/Coder.Test.csproj, with Go installed).🤖 Generated with Claude Code
https://claude.ai/code/session_017vfJW3mc54mR7dMPMARSVv