@@ -2408,27 +2408,28 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
2408
2408
auto *const pack1 = pattern1->getAs<PackType>();
2409
2409
auto *const pack2 = pattern2->getAs<PackType>();
2410
2410
2411
- // If both sides are expanded or neither side is, just match them
2411
+ // If both sides are expanded or neither side is, proceed to matching them
2412
2412
// directly.
2413
- if ((bool)pack1 == (bool)pack2) {
2414
- return matchTypes(pattern1, pattern2, kind, flags, locator);
2415
- }
2416
-
2417
- // We have something like `Foo<$T0>` vs `Pack{Foo<Int>, Foo<String>}` or vice
2418
- // versa. We're going to bind $T0 to Pack{Int, String}.
2419
- if (pack1) {
2420
- pack2 = replaceTypeVariablesWithFreshPacks(*this, pattern2, pack1, locator);
2421
- } else {
2422
- pack1 = replaceTypeVariablesWithFreshPacks(*this, pattern1, pack2, locator);
2423
- }
2424
-
2425
- if (pack1 && pack2) {
2426
- addConstraint(kind, pack1, pack2, locator);
2413
+ // Otherwise, we have something like `Foo<$T0>` vs.
2414
+ // `Pack{Foo<Int>, Foo<String>}` or vice versa.
2415
+ // We're going to bind `$T0` to `Pack{Int, String}` and unfold `Foo<$T0>` into
2416
+ // `Pack{Foo<$T3>, Foo<$T4>} first.
2417
+ if ((bool)pack1 != (bool)pack2) {
2418
+ if (pack1) {
2419
+ pattern2 =
2420
+ replaceTypeVariablesWithFreshPacks(*this, pattern2, pack1, locator);
2421
+ } else {
2422
+ pattern1 =
2423
+ replaceTypeVariablesWithFreshPacks(*this, pattern1, pack2, locator);
2424
+ }
2427
2425
2428
- return getTypeMatchSuccess();
2426
+ if (!(pattern1 && pattern2)) {
2427
+ return getTypeMatchFailure(locator);
2428
+ }
2429
2429
}
2430
2430
2431
- return getTypeMatchFailure(locator);
2431
+ // Continue matching.
2432
+ return matchTypes(pattern1, pattern2, kind, flags, locator);
2432
2433
}
2433
2434
2434
2435
/// Check where a representation is a subtype of another.
0 commit comments