From 1fb3c1536587d6ed085f13af78101cbfb3481dca Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:28:13 -0800 Subject: Fix overload resolution for `ModuleDeclarationDecl` (#6483) * Fix overload resolution for `MemberExp`r's base expression Also fixed an issue where `ModuleDeclarationDecl` priority during overload resolution was inverted. * Made the fix slightly simpler.. * Update overload-resolve.slang --- source/slang/slang-check-expr.cpp | 6 +++++- source/slang/slang-check-overload.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 1fb2b336f..b249bb343 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -4848,17 +4848,21 @@ Expr* SemanticsVisitor::maybeInsertImplicitOpForMemberBase( // baseExpr = maybeOpenExistential(baseExpr); + // In case our base expressin is still overloaded, we can perform + // some more refinement. + // // Handle the case of an overloaded base expression // here, in case we can use the name of the member to // disambiguate which of the candidates is meant, or if // we can return an overloaded result. + // if (auto overloadedExpr = as(baseExpr)) { // If a member (dynamic or static) lookup result contains both the actual definition // and the interface definition obtained from inheritance, we want to filter out // the interface definitions. LookupResult filteredLookupResult; - for (auto lookupResult : overloadedExpr->lookupResult2) + for (auto lookupResult : overloadedExpr->lookupResult2.items) { bool shouldRemove = false; if (lookupResult.declRef.getParent().as()) diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 01cd303c7..5e55eb70f 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1345,7 +1345,7 @@ int SemanticsVisitor::CompareLookupResultItems( bool leftIsModule = (as(left.declRef) != nullptr); bool rightIsModule = (as(right.declRef) != nullptr); if (leftIsModule != rightIsModule) - return int(rightIsModule) - int(leftIsModule); + return int(leftIsModule) - int(rightIsModule); // If both are interface requirements, prefer the more derived interface. if (leftIsInterfaceRequirement && rightIsInterfaceRequirement) -- cgit v1.2.3