From 5dc3c2f57963de93ad03724a01ea48b8585dc15a Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 25 Oct 2023 07:50:14 -0700 Subject: Add `IArray`. (#3281) * Initial support for generic interfaces. * Cleanup. * Add generic syntax for interfaces. * Add `IArray`. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-check-constraint.cpp | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-check-constraint.cpp') diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index 996b88f48..8fd4061db 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -716,8 +716,38 @@ namespace Slang if (typeParamDecl->parentDecl == constraints.genericDecl) return TryUnifyTypeParam(constraints, typeParamDecl, fst); - // can't be unified if they refer to different declarations. - if (fstDeclRef.getDecl() != sndDeclRef.getDecl()) return false; + // If they refer to different declarations, we need to check if one type's super type + // matches the other type, if so we can unify them. + if (fstDeclRef.getDecl() != sndDeclRef.getDecl()) + { + { + auto fstTypeInheritanceInfo = getShared()->getInheritanceInfo(fstDeclRefType); + for (auto supType : fstTypeInheritanceInfo.facets) + { + if (supType->origin.declRef.getDecl() == sndDeclRef.getDecl()) + { + fstDeclRef = supType->origin.declRef; + goto endMatch; + } + } + } + // try the other direction + { + auto sndTypeInheritanceInfo = getShared()->getInheritanceInfo(sndDeclRefType); + for (auto supType : sndTypeInheritanceInfo.facets) + { + if (supType->origin.declRef.getDecl() == fstDeclRef.getDecl()) + { + sndDeclRef = supType->origin.declRef; + goto endMatch; + } + } + } + endMatch:; + // If they still refer to different decls, then we can't unify them. + if (fstDeclRef.getDecl() != sndDeclRef.getDecl()) + return false; + } // next we need to unify the substitutions applied // to each declaration reference. -- cgit v1.2.3