From ceb3af59f797ec60249debd614db13dd6902de12 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 28 Feb 2025 00:57:56 -0800 Subject: Fix member lookup in left hand side of `where` clause. (#6490) Co-authored-by: Ellie Hermaszewska --- source/slang/slang-check-inheritance.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/slang') diff --git a/source/slang/slang-check-inheritance.cpp b/source/slang/slang-check-inheritance.cpp index b44858874..cef9b6a09 100644 --- a/source/slang/slang-check-inheritance.cpp +++ b/source/slang/slang-check-inheritance.cpp @@ -460,6 +460,9 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo( } } + bool selfIsGenericParamType = + isDeclRefTypeOf(selfType) != nullptr; + for (auto constraintDeclRef : getMembersOfType(astBuilder, genericDeclRef)) { @@ -471,6 +474,13 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo( // Check only the sub-type. visitor.CheckConstraintSubType(constraintDeclRef.getDecl()->sub); auto sub = constraintDeclRef.getDecl()->sub; + + // If the sub-type part of the generic constraint is a member expression, it can't + // possibly be defining a constraint for a generic type parameter, so we skip it + // to avoid circular checking on the generic param type. + if (selfIsGenericParamType && as(sub.exp)) + continue; + if (!sub.type) sub = visitor.TranslateTypeNodeForced(sub); auto subType = constraintDeclRef.substitute(astBuilder, sub.type); -- cgit v1.2.3