Skip to content

Strip enum member type name from sibling references in initializers#730

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:fix-strip-enum-member-references
Jul 13, 2026
Merged

Strip enum member type name from sibling references in initializers#730
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:fix-strip-enum-member-references

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes #576.

With strip-enum-member-type-name, member declarations were stripped but references to sibling members inside an initializer kept the enum type prefix, so the output referenced undefined names:

public enum WGPUInstanceBackend
{
    Vulkan = 1 << 0,
    Metal = 1 << 2,
    Primary = WGPUInstanceBackend_Vulkan | WGPUInstanceBackend_Metal,  // undefined
}

VisitDeclRefExpr computed the reference name with EscapeName and never applied the same stripping used when emitting the declaration (EscapeAndStripEnumMemberName in VisitEnumConstantDecl). Apply that transform to enum constant references, keyed off the referenced member's own enum type name, so references match their declarations:

    Primary = Vulkan | Metal,

EscapeAndStripEnumMemberName is a no-op when the option is off, so non-strip output is byte-identical (verified: no golden changed). Anonymous enums are left untouched, and cross-enum references still resolve via the existing using static path.

Added StripEnumMemberReferenceTest. Build 0 warning / 0 error; full suite green.

Note

This PR description and the code change were drafted by Copilot on my behalf.

When strip-enum-member-type-name is enabled, only the member declarations were
stripped; references to sibling members inside an initializer expression kept the
enum type prefix, producing code that referenced undefined names. Apply the same
EscapeAndStripEnumMemberName transform to enum constant references so they match
the stripped declarations.

Fixes dotnet#576

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding merged commit c048439 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the fix-strip-enum-member-references branch July 13, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect enum generation when using "strip-enum-member-type-name"

1 participant