diff options
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 6 | ||||
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 2 | ||||
| -rw-r--r-- | tests/language-feature/namespaces/namespace-import/overload-resolve.slang | 25 |
3 files changed, 31 insertions, 2 deletions
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<OverloadedExpr>(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<InterfaceDecl>()) 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<ModuleDeclarationDecl>(left.declRef) != nullptr); bool rightIsModule = (as<ModuleDeclarationDecl>(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) diff --git a/tests/language-feature/namespaces/namespace-import/overload-resolve.slang b/tests/language-feature/namespaces/namespace-import/overload-resolve.slang new file mode 100644 index 000000000..0b483d916 --- /dev/null +++ b/tests/language-feature/namespaces/namespace-import/overload-resolve.slang @@ -0,0 +1,25 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj + +module test; + +namespace test +{ + vector<uint, N> f<int N>(vector<uint, N> x) + { + return x; + } +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int tid = dispatchThreadID.x; + int inVal = tid; + // Should be able to resolve 'test' properly (and not get confused by the module declaration with the same name) + int outVal = test.f<3>(vector<uint, 3>(1, 2, 3)).y; + outputBuffer[tid] = outVal; + // CHECK: 2 +} |
