diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-14 18:41:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-14 18:41:48 -0700 |
| commit | 071f1b6062b459928ebfd6f2f60a8d6ad021112b (patch) | |
| tree | 2ba65eb40f39701db6fc775a9258ec8079d161a0 /source/slang/slang-check-conformance.cpp | |
| parent | 35a3d32c87f079749f6b100d01b289c3da02d7d6 (diff) | |
Variadic Generics Part 1: parsing and type checking. (#4833)
Diffstat (limited to 'source/slang/slang-check-conformance.cpp')
| -rw-r--r-- | source/slang/slang-check-conformance.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp index 0ff4bfed4..9a44cbbb4 100644 --- a/source/slang/slang-check-conformance.cpp +++ b/source/slang/slang-check-conformance.cpp @@ -232,7 +232,35 @@ namespace Slang } return nullptr; } - + else if (auto subTypePack = as<ConcreteTypePack>(subType)) + { + // A type pack (T0, T1, ...) is a subtype of supType, if each of its elements + // is a subtype of the supType. + ShortList<SubtypeWitness*> elementWitnesses; + for (Index i = 0; i < subTypePack->getTypeCount(); i++) + { + auto elementWitness = isSubtype(subTypePack->getElementType(i), superType, IsSubTypeOptions::None); + if (!elementWitness) + return nullptr; + elementWitnesses.add(elementWitness); + } + return m_astBuilder->getSubtypeWitnessPack(subType, superType, elementWitnesses.getArrayView().arrayView); + } + else if (auto expandType = as<ExpandType>(subType)) + { + // A expand type `expand patternType, captureList` is a subtype of supType, if patternType is a subtype of supType. + auto elementWitness = isSubtype(expandType->getPatternType(), superType, IsSubTypeOptions::None); + if (!elementWitness) + return nullptr; + return m_astBuilder->getExpandSubtypeWitness(subType, superType, elementWitness); + } + else if (auto eachType = as<EachType>(subType)) + { + auto elementWitness = isSubtype(eachType->getElementType(), superType, IsSubTypeOptions::None); + if (!elementWitness) + return nullptr; + return m_astBuilder->getEachSubtypeWitness(subType, superType, elementWitness); + } // default is failure return nullptr; } |
