Skip to content

Commit 1fb3c15

Browse files
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
1 parent 3c096a7 commit 1fb3c15

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

source/slang/slang-check-expr.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -4848,17 +4848,21 @@ Expr* SemanticsVisitor::maybeInsertImplicitOpForMemberBase(
48484848
//
48494849
baseExpr = maybeOpenExistential(baseExpr);
48504850

4851+
// In case our base expressin is still overloaded, we can perform
4852+
// some more refinement.
4853+
//
48514854
// Handle the case of an overloaded base expression
48524855
// here, in case we can use the name of the member to
48534856
// disambiguate which of the candidates is meant, or if
48544857
// we can return an overloaded result.
4858+
//
48554859
if (auto overloadedExpr = as<OverloadedExpr>(baseExpr))
48564860
{
48574861
// If a member (dynamic or static) lookup result contains both the actual definition
48584862
// and the interface definition obtained from inheritance, we want to filter out
48594863
// the interface definitions.
48604864
LookupResult filteredLookupResult;
4861-
for (auto lookupResult : overloadedExpr->lookupResult2)
4865+
for (auto lookupResult : overloadedExpr->lookupResult2.items)
48624866
{
48634867
bool shouldRemove = false;
48644868
if (lookupResult.declRef.getParent().as<InterfaceDecl>())

source/slang/slang-check-overload.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ int SemanticsVisitor::CompareLookupResultItems(
13451345
bool leftIsModule = (as<ModuleDeclarationDecl>(left.declRef) != nullptr);
13461346
bool rightIsModule = (as<ModuleDeclarationDecl>(right.declRef) != nullptr);
13471347
if (leftIsModule != rightIsModule)
1348-
return int(rightIsModule) - int(leftIsModule);
1348+
return int(leftIsModule) - int(rightIsModule);
13491349

13501350
// If both are interface requirements, prefer the more derived interface.
13511351
if (leftIsInterfaceRequirement && rightIsInterfaceRequirement)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj
2+
3+
module test;
4+
5+
namespace test
6+
{
7+
vector<uint, N> f<int N>(vector<uint, N> x)
8+
{
9+
return x;
10+
}
11+
}
12+
13+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
14+
RWStructuredBuffer<int> outputBuffer;
15+
16+
[numthreads(1, 1, 1)]
17+
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
18+
{
19+
int tid = dispatchThreadID.x;
20+
int inVal = tid;
21+
// Should be able to resolve 'test' properly (and not get confused by the module declaration with the same name)
22+
int outVal = test.f<3>(vector<uint, 3>(1, 2, 3)).y;
23+
outputBuffer[tid] = outVal;
24+
// CHECK: 2
25+
}

0 commit comments

Comments
 (0)