Repository navigation
Escape keyword-named enum members in C++ and Rust [patch] - #365
Merged
Merged
Conversation
CppGenerator and RustGenerator wrote enumeration members verbatim, so a member named `public` (C++) or `type` (Rust) produced output that failed to compile. Both now write each member through EscapeIdentifier, and a sibling's value that names it is rewritten to the same spelling. EscapeReference also escapes the last word of a `::` path, so a reference written as Kind::type or Access::public matches the declaration. The words before it stay as written. Fixes #364 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5wGJLhri3KXBeZJwH
|
This was referenced Oct 30, 2026
Merged
matt-edmondson
pushed a commit
that referenced
this pull request
Nov 4, 2026
Resolves the conflict in ReservedWordIdentifierTests.cs with #365, which added its enum tests at the same place. Both sets of tests are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5wGJLhri3KXBeZJwH
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 #364
What changed
CppGeneratorandRustGeneratornow write each enumeration member throughEscapeIdentifier. A member namedpublicin C++ becomespublic_, and one namedtypein Rust becomesr#type.Hidden = private_ + 1, and in RustOther = Kind::r#type as isize + 1. Before this change the Rust path passed the sibling through unescaped.LanguageGeneratorBase.EscapeReferencenow escapes the last word of a::path, soKind::typegivesKind::r#typeandAccess::publicgivesAccess::public_. The words before the last::are left as written, so path keywords likeSelf::andcrate::are not escaped.Tests
ReservedWordIdentifierTestshas two new tests,Rust_KeywordNamedEnumMembersCompileAndResolveandCpp_KeywordNamedEnumMembersCompileAndResolve. They declare keyword-named members, reference them through a::path and from a sibling's value, compile the output with rustc and g++, and run a driver.expected identifier, found keyword `type`and g++ reportsexpected identifier before 'public'.Generated by Claude Code