summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-constraint.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-09-05 11:24:19 -0700
committerGitHub <noreply@github.com>2024-09-05 11:24:19 -0700
commitd655302465457c5d3285ae5339201a0769cc38dc (patch)
tree4c0946ba4ea4879831133370d2203f569c135c35 /source/slang/slang-check-constraint.cpp
parenta88055c6f5190ca62bb4aa853b4f0fa11546278f (diff)
Support `where` clause and type equality constraint. (#4986)
* Support `where` clause. * Fix. * Fix parser. * Enhance test to cover traditional __generic syntax. * Update user-guide. * Support `where` clause on associatedtype. * Fix. * Put in more comments.
Diffstat (limited to 'source/slang/slang-check-constraint.cpp')
-rw-r--r--source/slang/slang-check-constraint.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp
index 3e3ed5297..90b0e44f5 100644
--- a/source/slang/slang-check-constraint.cpp
+++ b/source/slang/slang-check-constraint.cpp
@@ -648,7 +648,7 @@ namespace Slang
else if (auto subEachType = as<EachType>(constraintDeclRef.getDecl()->sub.type))
constrainedGenericParams.add(as<DeclRefType>(subEachType->getElementType())->getDeclRef().getDecl());
- if (sub->equals(sup))
+ if (sub->equals(sup) && isDeclRefTypeOf<InterfaceDecl>(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
@@ -674,6 +674,14 @@ namespace Slang
sup,
system->additionalSubtypeWitnesses ? IsSubTypeOptions::NoCaching : IsSubTypeOptions::None);
}
+
+ if (constraintDecl->isEqualityConstraint)
+ {
+ // If constraint is an equality constraint, we need to make sure
+ // the witness is equality witness.
+ if (!isTypeEqualityWitness(subTypeWitness))
+ subTypeWitness = nullptr;
+ }
if(subTypeWitness)
{