@@ -2405,40 +2405,30 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
24052405 }
24062406 }
24072407
2408+ auto *const pack1 = pattern1->getAs<PackType>();
2409+ auto *const pack2 = pattern2->getAs<PackType>();
2410+
24082411 // If both sides are expanded or neither side is, just match them
24092412 // directly.
2410- if (pattern1->is<PackType>() == pattern2->is<PackType>() ) {
2413+ if ((bool)pack1 == (bool)pack2 ) {
24112414 return matchTypes(pattern1, pattern2, kind, flags, locator);
2415+ }
24122416
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);
24302421 } 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+ }
24392424
2440- return getTypeMatchFailure(locator);
2425+ if (pack1 && pack2) {
2426+ addConstraint(kind, pack1, pack2, locator);
2427+
2428+ return getTypeMatchSuccess();
24412429 }
2430+
2431+ return getTypeMatchFailure(locator);
24422432}
24432433
24442434/// Check where a representation is a subtype of another.
0 commit comments