Skip to content

Commit 956ede9

Browse files
committed
Filter lookup results from interfaces in visitMemberExpr.
Fixes shader-slang#1377
1 parent 7d4432b commit 956ede9

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

source/slang/slang-check-expr.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -1826,10 +1826,38 @@ namespace Slang
18261826
//
18271827
expr->baseExpression = maybeOpenExistential(expr->baseExpression);
18281828

1829-
// TODO: Handle the case of an overloaded base expression
1829+
// Handle the case of an overloaded base expression
18301830
// here, in case we can use the name of the member to
18311831
// disambiguate which of the candidates is meant, or if
18321832
// we can return an overloaded result.
1833+
if (auto overloadedExpr = as<OverloadedExpr>(expr->baseExpression))
1834+
{
1835+
if (overloadedExpr->base)
1836+
{
1837+
// If a member (dynamic or static) lookup result contains both the actual definition
1838+
// and the interface definition obtained from inheritance, we want to filter out
1839+
// the interface definitions.
1840+
LookupResult filteredLookupResult;
1841+
for (auto lookupResult : overloadedExpr->lookupResult2)
1842+
{
1843+
bool shouldRemove = false;
1844+
if (lookupResult.declRef.getParent().as<InterfaceDecl>())
1845+
shouldRemove = true;
1846+
if (!shouldRemove)
1847+
{
1848+
filteredLookupResult.items.add(lookupResult);
1849+
}
1850+
}
1851+
if (filteredLookupResult.items.getCount() == 1)
1852+
filteredLookupResult.item = filteredLookupResult.items.getFirst();
1853+
expr->baseExpression = createLookupResultExpr(
1854+
expr->name,
1855+
filteredLookupResult,
1856+
overloadedExpr->base,
1857+
overloadedExpr->loc);
1858+
}
1859+
// TODO: handle other cases of OverloadedExpr that need filtering.
1860+
}
18331861

18341862
auto & baseType = expr->baseExpression->type;
18351863

tests/compute/assoctype-lookup.slang

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// assoctype-nested.slang
2+
3+
// Confirm that an associated type can be correctly looked up.
4+
5+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu
6+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
7+
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
8+
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
9+
10+
interface IBoneWeightSet
11+
{
12+
associatedtype PackedType;
13+
};
14+
15+
struct StandardBoneWeightSet : IBoneWeightSet
16+
{
17+
struct PackedType
18+
{
19+
uint boneIds : BONEIDS;
20+
uint boneWeights : BONEWEIGHTS;
21+
};
22+
PackedType field;
23+
};
24+
25+
interface IVertexFormat
26+
{
27+
associatedtype BoneWeightSet : IBoneWeightSet;
28+
};
29+
30+
struct VertexFormat<TBoneWeightSet : IBoneWeightSet> : IVertexFormat
31+
{
32+
typedef TBoneWeightSet BoneWeightSet;
33+
TBoneWeightSet.PackedType weightSet;
34+
};
35+
36+
struct OutputType
37+
{
38+
VertexFormat<StandardBoneWeightSet>.BoneWeightSet.PackedType field;
39+
};
40+
41+
int test(int val)
42+
{
43+
OutputType rs;
44+
rs.field.boneIds = 256;
45+
return rs.field.boneIds;
46+
}
47+
48+
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
49+
RWStructuredBuffer<int> gOutputBuffer;
50+
51+
[numthreads(4, 1, 1)]
52+
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
53+
{
54+
uint tid = dispatchThreadID.x;
55+
int inputVal = tid;
56+
int outputVal = test(inputVal);
57+
gOutputBuffer[tid] = outputVal;
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
100
2+
100
3+
100
4+
100

0 commit comments

Comments
 (0)