Repository navigation
Rename member references in C, Go, Rust and JavaScript enum values [patch] - #265
Merged
Merged
Conversation
…atch] An enum member's value may name another member (ReadWrite = Read | Write), but C and Go prefix their members, Rust scopes them and reads a variant as a value only through a cast, and a JavaScript object literal cannot read its own properties. The value text was copied verbatim, so the reference named something that was never declared. Whole-word sibling references are now rewritten to the generator's own spelling: Perm_Read in C, PermRead in Go, Perm::Read as i32 (or isize) in Rust, and the referenced member's value in JavaScript. Fixes #258 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175VbFC9TAs3FcivXVHTFum
|
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 #258
Before:
EnumMember.Valueis documented as allowing a reference to another member (ReadWrite = Read | Write). The C, Go, Rust and JavaScript generators copied that text as-is, but each of them renames or scopes its members. The output therefore referred toRead, which was never declared:'Read' undeclaredundefined: ReadReferenceErroron loadAfter: the new helper
LanguageGeneratorBase.RenameSiblingMembersrewrites each whole-word reference to a sibling member using the name that generator gave the member:Perm_Read, viaSpellEnumMemberPermRead, viaPrefixedPerm::Read as i32, cast to the#[repr]type, or toisizewhen no representation is fixedReadWrite: 1 | 2,Next: (1 | 2) + 1A word that only contains a member's name (
ReadMask) is left alone, as is a reference someone already qualified (Other.Read,X::Read). C#, C++ and Python already handled this correctly and are unchanged.Tests:
EnumSiblingReferenceTestsbuilds and runs the issue'sPermenum with gcc,go run, rustc (with#[repr(i32)]and with no repr) and node, and checks that the output isReadWrite == 3,Next == 4. It also has one unit test for the qualified-reference and longer-word cases. With the generator changes reverted, all 6 tests fail with the errors the issue lists. With the changes, all pass. Full suite: 1289 passed, 0 failed.Note: #263 also edits
RustGenerator.GenerateEnumDeclaration(it adds the#[derive]line). The hunks are next to each other but don't overlap.Generated by Claude Code