Disambiguate nested record names that clash with a sibling field#736
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
A named nested record is legal in C even when a sibling field shares its name, but the two map to a nested type and a field of the same name in C#, which is a CS0102 clash. Auto-rename the type using the anonymous-record naming (e.g. '_Name_e__Struct') so the declaration and every reference stay consistent, and emit a warning once per rename pointing at the new options. Add '--remap-type' and '--remap-field' so a type and a field that share a name can be disambiguated explicitly; these take precedence over the general '--remap' and are keyed by cursor kind so resolving a field's type no longer picks up a field remapping. The clash is detected via the lexical parent so it also fires in C, where a nested record is semantically promoted to the enclosing scope yet still emitted nested. Fixes dotnet#606 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 #606.
A named nested record is legal in C even when a sibling field shares its name, but the two map to a nested type and a field of the same name in the same C# parent, which is a
CS0102clash. For example:previously emitted both
public partial struct GpuCaptureParametersandpublic ... GpuCaptureParameters;in the same struct.This does both of the things suggested on the issue:
_GpuCaptureParameters_e__Struct) so the declaration and every reference resolve to the same type. A warning is emitted once per rename pointing the user at the explicit options:--remap-type/--remap-field. These disambiguate a type vs a field that share a name. They take precedence over the general--remapand are keyed by cursor kind, so resolving a field's type no longer picks up a--remap-fieldentry (and vice versa).A couple of notable details:
LexicalDeclContext), not the semantic one. In C a nested record is semantically promoted to the enclosing scope, yet it is still emitted nested based on where it lexically appears -- so the semantic parent would miss the clash for exactly the C headers that hit this.GetRemappedCursorName, so the rename/override is re-applied there via a small shared helper to keep the declaration and reference in sync.Verified the generated output compiles (no
CS0102) for the default,--remap-type, and--remap-fieldcases. AddedUnionFieldTypeNameClashTestcovering all three. Full generator suite green (Failed: 0, 3724 passed) with zero golden churn.Note
This PR description and the code changes were drafted with Copilot.