@@ -3880,19 +3880,6 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
38803880 return getTypeMatchFailure(locator);
38813881 }
38823882
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-
38963883 TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
38973884
38983885 // Handle existential metatypes.
@@ -8318,6 +8305,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
83188305 ConstraintKind kind,
83198306 ConstraintLocatorBuilder locator,
83208307 TypeMatchOptions flags) {
8308+
83218309 if (auto proto = protocol->getAs<ProtocolType>()) {
83228310 return simplifyConformsToConstraint(type, proto->getDecl(), kind,
83238311 locator, flags);
@@ -8326,6 +8314,28 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
83268314 // Dig out the fixed type to which this type refers.
83278315 type = getFixedTypeRecursive(type, flags, /*wantRValue=*/true);
83288316
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+
83298339 return matchExistentialTypes(type, protocol, kind, flags, locator);
83308340}
83318341
0 commit comments