Skip to content

Commit 12d21e4

Browse files
committed
Sema: Handle PackExpansionType inside PackType when splitting up ConformsTo/SubclassOf constraints
1 parent 2dd6d24 commit 12d21e4

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7472,8 +7472,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifySubclassOfConstraint(
74727472
// smaller constraints.
74737473
if (auto *packType = type->getAs<PackType>()) {
74747474
for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
7475-
addConstraint(ConstraintKind::SubclassOf, packType->getElementType(i),
7476-
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
7475+
auto eltType = packType->getElementType(i);
7476+
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
7477+
// FIXME: Locator element for pack expansion pattern
7478+
addConstraint(ConstraintKind::SubclassOf, packExpansionType->getPatternType(),
7479+
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
7480+
} else {
7481+
addConstraint(ConstraintKind::SubclassOf, eltType,
7482+
classType, locator.withPathElement(LocatorPathElt::PackElement(i)));
7483+
}
74777484
}
74787485

74797486
return SolutionKind::Solved;
@@ -7583,9 +7590,18 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
75837590
// smaller constraints.
75847591
if (auto *packType = type->getAs<PackType>()) {
75857592
for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
7586-
addConstraint(ConstraintKind::ConformsTo, packType->getElementType(i),
7587-
protocol->getDeclaredInterfaceType(),
7588-
locator.withPathElement(LocatorPathElt::PackElement(i)));
7593+
auto eltType = packType->getElementType(i);
7594+
if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
7595+
// FIXME: Locator element for pack expansion pattern
7596+
addConstraint(ConstraintKind::ConformsTo,
7597+
packExpansionType->getPatternType(),
7598+
protocol->getDeclaredInterfaceType(),
7599+
locator.withPathElement(LocatorPathElt::PackElement(i)));
7600+
} else {
7601+
addConstraint(ConstraintKind::ConformsTo, eltType,
7602+
protocol->getDeclaredInterfaceType(),
7603+
locator.withPathElement(LocatorPathElt::PackElement(i)));
7604+
}
75897605
}
75907606

75917607
return SolutionKind::Solved;

0 commit comments

Comments
 (0)