Skip to content

Commit aa28fe1

Browse files
committed
CSSimplify: Continue matching instead of adding constraint in matchPackExpansionTypes
This ensures that the flags are type matching flags are respected
1 parent 352bddd commit aa28fe1

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,27 +2408,28 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
24082408
auto *const pack1 = pattern1->getAs<PackType>();
24092409
auto *const pack2 = pattern2->getAs<PackType>();
24102410

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
24122412
// 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+
}
24272425

2428-
return getTypeMatchSuccess();
2426+
if (!(pattern1 && pattern2)) {
2427+
return getTypeMatchFailure(locator);
2428+
}
24292429
}
24302430

2431-
return getTypeMatchFailure(locator);
2431+
// Continue matching.
2432+
return matchTypes(pattern1, pattern2, kind, flags, locator);
24322433
}
24332434

24342435
/// Check where a representation is a subtype of another.

0 commit comments

Comments
 (0)