@@ -2405,40 +2405,30 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
2405
2405
}
2406
2406
}
2407
2407
2408
+ auto *const pack1 = pattern1->getAs<PackType>();
2409
+ auto *const pack2 = pattern2->getAs<PackType>();
2410
+
2408
2411
// If both sides are expanded or neither side is, just match them
2409
2412
// directly.
2410
- if (pattern1->is<PackType>() == pattern2->is<PackType>() ) {
2413
+ if ((bool)pack1 == (bool)pack2 ) {
2411
2414
return matchTypes(pattern1, pattern2, kind, flags, locator);
2415
+ }
2412
2416
2413
- // If the right hand side is expanded, we have something like
2414
- // Foo<$T0>... vs Pack{Foo<Int>, Foo<String>}...; We're going to
2415
- // bind $T0 to Pack{Int, String}.
2416
- } else if (!pattern1->is<PackType>() && pattern2->is<PackType>()) {
2417
- if (auto *pack2 = pattern2->getAs<PackType>()) {
2418
- if (auto *pack1 = replaceTypeVariablesWithFreshPacks(
2419
- *this, pattern1, pack2, locator)) {
2420
- addConstraint(kind, pack1, pack2, locator);
2421
- return getTypeMatchSuccess();
2422
- }
2423
- }
2424
-
2425
- return getTypeMatchFailure(locator);
2426
-
2427
- // If the left hand side is expanded, we have something like
2428
- // Pack{Foo<Int>, Foo<String>}... vs Foo<$T0>...; We're going to
2429
- // bind $T0 to Pack{Int, String}.
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);
2430
2421
} else {
2431
- assert(pattern1->is<PackType>() && !pattern2->is<PackType>());
2432
- if (auto *pack1 = pattern1->getAs<PackType>()) {
2433
- if (auto *pack2 = replaceTypeVariablesWithFreshPacks(
2434
- *this, pattern2, pack1, locator)) {
2435
- addConstraint(kind, pack1, pack2, locator);
2436
- return getTypeMatchSuccess();
2437
- }
2438
- }
2422
+ pack1 = replaceTypeVariablesWithFreshPacks(*this, pattern1, pack2, locator);
2423
+ }
2439
2424
2440
- return getTypeMatchFailure(locator);
2425
+ if (pack1 && pack2) {
2426
+ addConstraint(kind, pack1, pack2, locator);
2427
+
2428
+ return getTypeMatchSuccess();
2441
2429
}
2430
+
2431
+ return getTypeMatchFailure(locator);
2442
2432
}
2443
2433
2444
2434
/// Check where a representation is a subtype of another.
0 commit comments