From ea15647ba6bccb5ac48de5f4b80b8c2769d69b8f Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 7 Apr 2023 10:12:00 -0700 Subject: Diagnose on attempt to specialize with interface type. (#2780) * Diagnose on attempt to specialize with interface type. Fixes ##1445. * Enable fixed test. * Fix test. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-check-constraint.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source') diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index f96b5a484..6e9d73b61 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -469,6 +469,16 @@ namespace Slang auto sub = getSub(m_astBuilder, constraintDeclRef); auto sup = getSup(m_astBuilder, constraintDeclRef); + if (sub->equals(sup)) + { + // We are trying to use an interface type itself to conform to the + // type constraint. We can reach this case when the user code does + // not provide an explicit type parameter to specialize a generic + // and the type parameter cannot be inferred from any arguments. + // In this case, we should fail the constraint check. + return SubstitutionSet(); + } + // Search for a witness that shows the constraint is satisfied. auto subTypeWitness = tryGetSubtypeWitness(sub, sup); if(subTypeWitness) -- cgit v1.2.3