Fix shadowing of type names by variant case record names - #4899
Merged
bernardnormier merged 3 commits intoAug 28, 2026
Conversation
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
InsertCreativityHere
approved these changes
Aug 28, 2026
InsertCreativityHere
left a comment
Member
There was a problem hiding this comment.
Looks good to me!
Comment on lines
+135
to
+136
| // Inside the union record, the case record names shadow the type names of the enclosing namespace. We set | ||
| // currentNamespace to "" to generate fully qualified type names for the parameter list and the encode method. |
Member
There was a problem hiding this comment.
Big fan of adding a comment so we don't accidentally remove this again!
A slight tweak though, since this isn't something that always happens. In reality it should be rare.
Suggested change
| // Inside the union record, the case record names shadow the type names of the enclosing namespace. We set | |
| // currentNamespace to "" to generate fully qualified type names for the parameter list and the encode method. | |
| // Inside the union record, the case record names can shadow type names from the enclosing namespace. We set | |
| // currentNamespace to "" to generate fully qualified type names for the parameter list and the encode method. |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.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 #4896.
The variant enum mapping nests one case record per case inside the union record, so within the union body the case record names shadow same-namespace type names. The case parameter list and the case
Encodemethod now emit fully qualified type names (empty current namespace).The parameter list regressed in #4877; the
Encodemethod exposure predates it — a tagged (or otherwise lambda-encoded) field whose type name matches a case name produced code that binds the type name to the sibling case record (error CS8121). It went unnoticed because no variant enum had such a field.The new
ShadowedSymbolenum inVariantEnumTests.slicecovers both: a self-colliding case (MyStruct(v: MyStruct)), and colliding optional and tagged fields. Compiling the generated code is the regression test; #4898 tracks runtime coverage for struct-typed variant fields, a pre-existing test gap that is independent of shadowing.The second commit regenerates the checked-in
src/ZeroC.Slice.Symbols/Compilerfiles with the fixed generator: only the version stamps change, confirming the fix restores the exact output these files were generated with.What's Changed entry
Area: Slice codec