Fully qualify type names in enum variant nested record classes#4288
Merged
Fully qualify type names in enum variant nested record classes#4288
Conversation
When slicec-cs generates nested record classes for Slice enums with fields, the nested class name can shadow the field type name, causing CS8910 errors in C#. For example, `record class Enum(Enum V)` fails because the class name shadows the type. Fix by passing an empty namespace to field_type_string(), which forces all user-defined types to use fully qualified names with global:: prefix (e.g., `record class Enum(global::Ns.Enum V)`). Also remove the now-unused ContainerBuilder::add_fields method.
There was a problem hiding this comment.
Pull request overview
This PR updates the C# Slice code generator to avoid C# compiler CS8910 errors in generated enum-variant nested record classes by ensuring enum variant field types are always emitted with fully-qualified global::... user-defined type names.
Changes:
- Fully qualify user-defined types for enum variant primary-constructor parameters by calling
field_type_string(""). - Inline per-field generation in
enum_generator.rsinstead of relying on the removed helper. - Remove the now-unused
ContainerBuilder::add_fieldsmethod.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tools/slicec-cs/src/generators/enum_generator.rs | Forces global:: qualification for enum variant field types to avoid nested record name/type shadowing. |
| tools/slicec-cs/src/builders.rs | Removes unused ContainerBuilder::add_fields helper after generator logic was inlined. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
InsertCreativityHere
approved these changes
Mar 10, 2026
Member
InsertCreativityHere
left a comment
There was a problem hiding this comment.
Looks good to me!
Co-authored-by: Austin Henriksen <austin@zeroc.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.
Summary
record class Enum(Enum V))global::prefix for all user-defined types in enum variant primary constructor parametersContainerBuilder::add_fieldsmethod