mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user