@@ -3880,19 +3880,6 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
3880
3880
return getTypeMatchFailure(locator);
3881
3881
}
3882
3882
3883
- // ConformsTo constraints are generated when opening a generic
3884
- // signature with a RequirementKind::Conformance requirement, so
3885
- // we must handle pack types on the left by splitting up into
3886
- // smaller constraints.
3887
- if (auto *packType = type1->getAs<PackType>()) {
3888
- for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
3889
- addConstraint(kind, packType->getElementType(i), type2,
3890
- locator.withPathElement(LocatorPathElt::PackElement(i)));
3891
- }
3892
-
3893
- return getTypeMatchSuccess();
3894
- }
3895
-
3896
3883
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
3897
3884
3898
3885
// Handle existential metatypes.
@@ -8318,6 +8305,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8318
8305
ConstraintKind kind,
8319
8306
ConstraintLocatorBuilder locator,
8320
8307
TypeMatchOptions flags) {
8308
+
8321
8309
if (auto proto = protocol->getAs<ProtocolType>()) {
8322
8310
return simplifyConformsToConstraint(type, proto->getDecl(), kind,
8323
8311
locator, flags);
@@ -8326,6 +8314,28 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
8326
8314
// Dig out the fixed type to which this type refers.
8327
8315
type = getFixedTypeRecursive(type, flags, /*wantRValue=*/true);
8328
8316
8317
+ // ConformsTo constraints are generated when opening a generic
8318
+ // signature with a RequirementKind::Conformance requirement, so
8319
+ // we must handle pack types on the left by splitting up into
8320
+ // smaller constraints.
8321
+ if (auto *packType = type->getAs<PackType>()) {
8322
+ for (unsigned i = 0, e = packType->getNumElements(); i < e; ++i) {
8323
+ auto eltType = packType->getElementType(i);
8324
+ if (auto *packExpansionType = eltType->getAs<PackExpansionType>()) {
8325
+ auto patternLoc =
8326
+ locator.withPathElement(ConstraintLocator::PackExpansionPattern);
8327
+ addConstraint(ConstraintKind::ConformsTo,
8328
+ packExpansionType->getPatternType(), protocol,
8329
+ patternLoc);
8330
+ } else {
8331
+ addConstraint(ConstraintKind::ConformsTo, eltType, protocol,
8332
+ locator.withPathElement(LocatorPathElt::PackElement(i)));
8333
+ }
8334
+ }
8335
+
8336
+ return SolutionKind::Solved;
8337
+ }
8338
+
8329
8339
return matchExistentialTypes(type, protocol, kind, flags, locator);
8330
8340
}
8331
8341
0 commit comments