Qualify anonymous enum references with their backing class for exclude-using-statics-for-enums#733
Merged
tannergooding merged 1 commit intoJul 13, 2026
Conversation
…e-using-statics-for-enums When exclude-using-statics-for-enums is set, a cross-context enum constant reference is emitted as EnumName.Member. For an anonymous enum there is no generated enum type -- the members are emitted as constants on the enum's backing class (e.g. Methods) -- so qualifying with the __AnonymousEnum_* name produced a reference to a type that doesn't exist and didn't compile. Qualify with the backing class instead, mirroring the anonymous-enum handling on the using-statics path. Fixes dotnet#681 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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 #681.
With
exclude-using-statics-for-enums, a cross-context enum constant reference is emitted asEnumName.Member. For an anonymous enum there is no generated enum type — the members are lowered toconstfields on the enum's backing class (Methodshere) — so qualifying with the synthesized__AnonymousEnum_*name referenced a type that doesn't exist:VisitDeclRefExpr'sDontUseUsingStaticsForEnumsbranch wroteenumNameunconditionally. The using-statics branch already special-cases anonymous enums viaGetClass(enumName); this mirrors that, so the reference now qualifies with the backing class:Verified live:
exclude-using-statics-for-enums→Methods.MyEnum1_Value1(was__AnonymousEnum_*.)using static ...Methods;+ unqualifiedMyEnum1_Value1exclude-using-statics-for-enumsunchanged →MyEnum1.MyEnum1_Value1Added
AnonymousEnumReferenceExcludeUsingStaticsTest. Build0 warning / 0 error; full suite green with no golden changes.Note
This PR description and the code change were drafted by Copilot on my behalf.