CSSimplify: Continue matching instead of adding constraint in matchPackExpansionTypes

This ensures that type matching flags are propagated.
This commit is contained in:
Anthony Latsis
2024-12-13 11:33:27 +00:00
parent 352bddd9b2
commit 0b204828d5

View File

@@ -2408,27 +2408,28 @@ ConstraintSystem::matchPackExpansionTypes(PackExpansionType *expansion1,
auto *const pack1 = pattern1->getAs<PackType>();
auto *const pack2 = pattern2->getAs<PackType>();
// If both sides are expanded or neither side is, just match them
// If both sides are expanded or neither side is, proceed to matching them
// directly.
if ((bool)pack1 == (bool)pack2) {
return matchTypes(pattern1, pattern2, kind, flags, locator);
// Otherwise, we have something like `Foo<$T0>` vs.
// `Pack{Foo<Int>, Foo<String>}` or vice versa.
// We're going to bind `$T0` to `Pack{Int, String}` and unfold `Foo<$T0>` into
// `Pack{Foo<$T3>, Foo<$T4>} first.
if ((bool)pack1 != (bool)pack2) {
if (pack1) {
pattern2 =
replaceTypeVariablesWithFreshPacks(*this, pattern2, pack1, locator);
} else {
pattern1 =
replaceTypeVariablesWithFreshPacks(*this, pattern1, pack2, locator);
}
if (!(pattern1 && pattern2)) {
return getTypeMatchFailure(locator);
}
}
// We have something like `Foo<$T0>` vs `Pack{Foo<Int>, Foo<String>}` or vice
// versa. We're going to bind $T0 to Pack{Int, String}.
if (pack1) {
pack2 = replaceTypeVariablesWithFreshPacks(*this, pattern2, pack1, locator);
} else {
pack1 = replaceTypeVariablesWithFreshPacks(*this, pattern1, pack2, locator);
}
if (pack1 && pack2) {
addConstraint(kind, pack1, pack2, locator);
return getTypeMatchSuccess();
}
return getTypeMatchFailure(locator);
// Continue matching.
return matchTypes(pattern1, pattern2, kind, flags, locator);
}
/// Check where a representation is a subtype of another.