[CSSimplify] Bind for-in patterns to holes if element type is Any

If the element type is `Any` i.e. `for (x, y) in [] { ... }`
it would never match the pattern and the pattern (`rhs` = `(x, y)`)
doesn't have any other source of contextual information,
so instead of waiting for elements to become holes with an
unrelated fixes, let's proactively bind all of the pattern
elements to holes.

Resolves:  rdar://100343275
This commit is contained in:
Pavel Yaskevich
2022-10-28 11:19:29 -07:00
parent 2e51e96676
commit d56e62d65c

View File

@@ -6022,6 +6022,21 @@ bool ConstraintSystem::repairFailures(
// `Int` vs. `(_, _)`.
recordAnyTypeVarAsPotentialHole(rhs);
// If the element type is `Any` i.e. `for (x, y) in [] { ... }`
// it would never match and the pattern (`rhs` = `(x, y)`)
// doesn't have any other source of contextual information,
// so instead of waiting for elements to become holes with an
// unrelated fixes, let's proactively bind all of the pattern
// elemnts to holes here.
if (lhs->isAny()) {
rhs.visit([&](Type type) {
if (auto *typeVar = type->getAs<TypeVariableType>()) {
assignFixedType(typeVar,
PlaceholderType::get(getASTContext(), typeVar));
}
});
}
conversionsOrFixes.push_back(CollectionElementContextualMismatch::create(
*this, lhs, rhs, getConstraintLocator(locator)));
break;