From 071f1b6062b459928ebfd6f2f60a8d6ad021112b Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 14 Aug 2024 18:41:48 -0700 Subject: Variadic Generics Part 1: parsing and type checking. (#4833) --- source/slang/slang-check-conformance.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-check-conformance.cpp') 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(subType)) + { + // A type pack (T0, T1, ...) is a subtype of supType, if each of its elements + // is a subtype of the supType. + ShortList 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(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(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; } -- cgit v1.2.3