Skip to content

Commit ceb3af5

Browse files
Fix member lookup in left hand side of where clause. (#6490)
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
1 parent a09d554 commit ceb3af5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

source/slang/slang-check-inheritance.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
460460
}
461461
}
462462

463+
bool selfIsGenericParamType =
464+
isDeclRefTypeOf<GenericTypeParamDeclBase>(selfType) != nullptr;
465+
463466
for (auto constraintDeclRef :
464467
getMembersOfType<GenericTypeConstraintDecl>(astBuilder, genericDeclRef))
465468
{
@@ -471,6 +474,13 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo(
471474
// Check only the sub-type.
472475
visitor.CheckConstraintSubType(constraintDeclRef.getDecl()->sub);
473476
auto sub = constraintDeclRef.getDecl()->sub;
477+
478+
// If the sub-type part of the generic constraint is a member expression, it can't
479+
// possibly be defining a constraint for a generic type parameter, so we skip it
480+
// to avoid circular checking on the generic param type.
481+
if (selfIsGenericParamType && as<MemberExpr>(sub.exp))
482+
continue;
483+
474484
if (!sub.type)
475485
sub = visitor.TranslateTypeNodeForced(sub);
476486
auto subType = constraintDeclRef.substitute(astBuilder, sub.type);

tests/bugs/gh-6488-where-lookup.slang

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//TEST:SIMPLE(filecheck=CHECK): -target spirv
2+
3+
// CHECK: OpEntryPoint
4+
5+
interface IRealArray<T : __BuiltinFloatingPointType, int D> {}
6+
extension<T : __BuiltinFloatingPointType, int D> vector<T, D> : IRealArray<T, D> where T.Differential : __BuiltinFloatingPointType { }
7+
8+
9+
[numthreads(1,1,1)]
10+
void main()
11+
{}

0 commit comments

Comments
 (0)