From 88e221bad60ce20087fe2f8a85d506be36a6e6ca Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 30 Dec 2024 23:38:34 -0800 Subject: Fix requirement candidate lookup to prefer decls in the same paraent as the inheritance decl. (#5965) --- source/slang/slang-check-decl.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-check-decl.cpp') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index c9497ce54..3fea267ee 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -6541,7 +6541,25 @@ bool SemanticsVisitor::findWitnessForInterfaceRequirement( } } } - + if (lookupResult.isOverloaded()) + { + // If we found multiple members with the same name, + // we want to move the declarations in the same parent as inheritanceDecl + // to the front of the list, so that we always consider them first instead of + // the members declared in other extension decls. + // + Index front = 0; + auto parentOfInheritanceDecl = getParentAggTypeDeclBase(inheritanceDecl); + for (Index i = 0; i < lookupResult.items.getCount(); i++) + { + if (getParentAggTypeDeclBase(lookupResult.items[i].declRef.getDecl()) == + parentOfInheritanceDecl) + { + lookupResult.items.swapElements(i, front); + front++; + } + } + } // Iterate over the members and look for one that matches // the expected signature for the requirement. for (auto member : lookupResult) -- cgit v1.2.3