Skip to content

Qualify nested type references with their containing types#731

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:fix-nested-type-qualification
Jul 13, 2026
Merged

Qualify nested type references with their containing types#731
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:fix-nested-type-qualification

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Fixes #579.

A reference to a nested type was reduced to only its last :: segment, so using it from another scope emitted an unqualified name that doesn't resolve:

public void Method([NativeTypeName(""A::Inner &"")] Inner* inner)   // Inner is undefined here

In GetTypeName's TagType handling, the :: case did Split(""::"").Last() and dropped all qualification. Nested types are emitted as nested C# types, so a reference needs the containing type(s) as a prefix. Walk the enclosing RecordDecl chain (mirroring the existing idiom in VisitIndirectFieldDecl) and prepend each remapped name, while still flattening namespaces (only record parents are added):

public void Method([NativeTypeName(""A::Inner &"")] A.Inner* inner)

Verified against the full matrix:

  • A::Inner -> A.Inner (fields, params, return types, and the vtbl delegate signature)
  • A::B::Inner -> A.B.Inner (deep nesting)
  • A::Color (enum nested in a struct) -> A.Color
  • ns::Foo -> Foo (namespaces still flattened)

No existing golden output changed. Added NestedTypeReferenceTest. Build 0 warning / 0 error; full suite green.

Note

This PR description and the code change were drafted by Copilot on my behalf.

A reference to a nested type (e.g. A::Inner) was reduced to just its last name
segment, so referencing it from another scope produced an unqualified name that
doesn't resolve in C#. Walk the enclosing record decls and prefix them (A.Inner),
while continuing to flatten namespaces as before.

Fixes dotnet#579

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding merged commit c031768 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the fix-nested-type-qualification branch July 13, 2026 05:43
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.

Generating nested types are not sufficiently qualified

1 participant