Skip to content

Fix shadowing of type names by variant case record names - #4899

Merged
bernardnormier merged 3 commits into
icerpc:mainfrom
bernardnormier:fix-variant-case-shadowing
Aug 28, 2026
Merged

Fix shadowing of type names by variant case record names#4899
bernardnormier merged 3 commits into
icerpc:mainfrom
bernardnormier:fix-variant-case-shadowing

Conversation

@bernardnormier

Copy link
Copy Markdown
Member

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 Encode method now emit fully qualified type names (empty current namespace).

The parameter list regressed in #4877; the Encode method 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 ShadowedSymbol enum in VariantEnumTests.slice covers 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/Compiler files 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

  • Fixed the generated code for variant enums whose case names match the type names used by their fields.

bernardnormier and others added 2 commits August 27, 2026 15:34
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@externl externl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@InsertCreativityHere InsertCreativityHere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied, thanks.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bernardnormier
bernardnormier merged commit 339f347 into icerpc:main Aug 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variant enum case field types can be shadowed by the case record names

3 participants