diff options
| author | Yong He <yonghe@outlook.com> | 2023-10-25 07:50:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-25 22:50:14 +0800 |
| commit | 5dc3c2f57963de93ad03724a01ea48b8585dc15a (patch) | |
| tree | 072748b952eb03da7950110ed3a8f87da9b5e72f /source/slang/slang-check-constraint.cpp | |
| parent | f8bf75cf1ae0aeee155996a917c2925bc500f3e2 (diff) | |
Add `IArray`. (#3281)
* Initial support for generic interfaces.
* Cleanup.
* Add generic syntax for interfaces.
* Add `IArray`.
* Fix.
* Fix.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-constraint.cpp')
| -rw-r--r-- | source/slang/slang-check-constraint.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
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. |
