From b78a8ba006fc9253cd1fd88fb7dd1eacfa749dfa Mon Sep 17 00:00:00 2001 From: "Harsh Aggarwal (NVIDIA)" Date: Thu, 24 Apr 2025 10:11:30 +0530 Subject: Fix #6544: Properly format nested type names in extensions (#6769) * Fix #6544: Properly format nested type names in extensions Modify DeclRefBase::toText to properly handle types defined in extensions by qualifying them with their parent type name. This ensures getFullName() returns the full name like 'FullPrecisionOptimizer.State' instead of just '.State'. Also handle other nested types in structs/classes similarly. * Update extension reflection handling - with generics args and namespaces - stopping namespace inclusion for extension members - Update to use getTargetType() to handle the generic arguments - update test cases * Simplify code to remove using parentDecl --- source/slang/slang-ast-decl-ref.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ast-decl-ref.cpp b/source/slang/slang-ast-decl-ref.cpp index a44e5b817..1881f1b3c 100644 --- a/source/slang/slang-ast-decl-ref.cpp +++ b/source/slang/slang-ast-decl-ref.cpp @@ -334,29 +334,39 @@ void DeclRefBase::toText(StringBuilder& out) SubstitutionSet substSet(this); - List decls; - for (auto dd = getDecl(); dd; dd = dd->parentDecl) + // Build a list of parent DeclRefs instead of just Decls + List declRefs; + + for (DeclRefBase* dr = this; dr; dr = dr->getParent()) { + auto dd = dr->getDecl(); + + // If this declaration is an extension, add it and then stop gathering parents + if (as(dd)) + { + declRefs.add(dr); + break; // Stop gathering parent DeclRefs to exclude namespace + } + // Skip the module, file & include decls since their names are // considered "transparent" - // if (as(dd) || as(dd) || as(dd)) continue; // Skip base decls in generic containers. We will handle them when we handle the generic // decl. - // if (dd->parentDecl && as(dd->parentDecl)) continue; - decls.add(dd); + declRefs.add(dr); } - decls.reverse(); + declRefs.reverse(); bool first = true; - for (auto decl : decls) + for (auto declRef : declRefs) { + auto decl = declRef->getDecl(); if (!first) out << "."; first = false; @@ -387,8 +397,13 @@ void DeclRefBase::toText(StringBuilder& out) out << ">"; } } - - // TODO: What do we do about extensions? + } + else if (auto extDecl = as(decl)) + { + if (extDecl->targetType) + { + getTargetType(getCurrentASTBuilder(), getParent())->toText(out); + } } } } -- cgit v1.2.3