Skip to content

Fully qualify type names in enum variant nested record classes#4288

Merged
pepone merged 2 commits intomainfrom
fix/slicec-cs-enum-qualified-types
Mar 10, 2026
Merged

Fully qualify type names in enum variant nested record classes#4288
pepone merged 2 commits intomainfrom
fix/slicec-cs-enum-qualified-types

Conversation

@pepone
Copy link
Member

@pepone pepone commented Mar 10, 2026

Summary

  • Fix CS8910 errors in generated C# code for Slice enums with fields, where the nested record class name shadows the field type name (e.g., record class Enum(Enum V))
  • Force fully qualified type names with global:: prefix for all user-defined types in enum variant primary constructor parameters
  • Remove the now-unused ContainerBuilder::add_fields method

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.
Copilot AI review requested due to automatic review settings March 10, 2026 10:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.rs instead of relying on the removed helper.
  • Remove the now-unused ContainerBuilder::add_fields method.

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.

Copy link
Member

@InsertCreativityHere InsertCreativityHere left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Co-authored-by: Austin Henriksen <austin@zeroc.com>
@pepone pepone merged commit 1aa2bc5 into main Mar 10, 2026
12 checks passed
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.

3 participants