summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-inheritance.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-08-14 18:41:48 -0700
committerGitHub <noreply@github.com>2024-08-14 18:41:48 -0700
commit071f1b6062b459928ebfd6f2f60a8d6ad021112b (patch)
tree2ba65eb40f39701db6fc775a9258ec8079d161a0 /source/slang/slang-check-inheritance.cpp
parent35a3d32c87f079749f6b100d01b289c3da02d7d6 (diff)
Variadic Generics Part 1: parsing and type checking. (#4833)
Diffstat (limited to 'source/slang/slang-check-inheritance.cpp')
-rw-r--r--source/slang/slang-check-inheritance.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/source/slang/slang-check-inheritance.cpp b/source/slang/slang-check-inheritance.cpp
index 7320d0463..3e59c5e8d 100644
--- a/source/slang/slang-check-inheritance.cpp
+++ b/source/slang/slang-check-inheritance.cpp
@@ -266,7 +266,7 @@ namespace Slang
addDirectBaseType(baseType, satisfyingWitness);
}
}
- else if (auto genericTypeParamDeclRef = declRef.as<GenericTypeParamDecl>())
+ else if (auto genericTypeParamDeclRef = declRef.as<GenericTypeParamDeclBase>())
{
// The constraints placed on a generic type parameter are siblings of that
// parameter in its parent `GenericDecl`, so we need to enumerate all of
@@ -298,7 +298,14 @@ namespace Slang
//
auto subDeclRefType = as<DeclRefType>(subType);
if (!subDeclRefType)
- continue;
+ {
+ if (auto subEachType = as<EachType>(subType))
+ {
+ subDeclRefType = as<DeclRefType>(subEachType->getElementType());
+ }
+ if (!subDeclRefType)
+ continue;
+ }
if (subDeclRefType->getDeclRef() != genericTypeParamDeclRef)
continue;
@@ -922,6 +929,35 @@ namespace Slang
info.facets = mergedFacets;
return info;
}
+ else if (auto eachType = as<EachType>(type))
+ {
+ auto elementInheritanceInfo = getInheritanceInfo(eachType->getElementType());
+ SemanticsVisitor visitor(this);
+ auto directFacet = new(arena) Facet::Impl(
+ Facet::Kind::Type,
+ Facet::Directness::Self,
+ DeclRef<Decl>(),
+ type,
+ visitor.createTypeEqualityWitness(type));
+ Facet tail = directFacet;
+ for (auto facet : elementInheritanceInfo.facets)
+ {
+ if (facet->directness == Facet::Directness::Direct)
+ {
+ auto eachFacet = new(arena) Facet::Impl(
+ Facet::Kind::Type,
+ Facet::Directness::Direct,
+ facet->origin.declRef,
+ facet->origin.type,
+ astBuilder->getEachSubtypeWitness(type, facet->subtypeWitness->getSup(), facet->subtypeWitness));
+ tail->next = eachFacet;
+ tail = eachFacet;
+ }
+ }
+ InheritanceInfo info;
+ info.facets = FacetList(directFacet);
+ return info;
+ }
else
{
// As a fallback, any type not covered by the above cases will