Skip to content

Commit d56e62d

Browse files
committed
[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
1 parent 2e51e96 commit d56e62d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6022,6 +6022,21 @@ bool ConstraintSystem::repairFailures(
60226022
// `Int` vs. `(_, _)`.
60236023
recordAnyTypeVarAsPotentialHole(rhs);
60246024

6025+
// If the element type is `Any` i.e. `for (x, y) in [] { ... }`
6026+
// it would never match and the pattern (`rhs` = `(x, y)`)
6027+
// doesn't have any other source of contextual information,
6028+
// so instead of waiting for elements to become holes with an
6029+
// unrelated fixes, let's proactively bind all of the pattern
6030+
// elemnts to holes here.
6031+
if (lhs->isAny()) {
6032+
rhs.visit([&](Type type) {
6033+
if (auto *typeVar = type->getAs<TypeVariableType>()) {
6034+
assignFixedType(typeVar,
6035+
PlaceholderType::get(getASTContext(), typeVar));
6036+
}
6037+
});
6038+
}
6039+
60256040
conversionsOrFixes.push_back(CollectionElementContextualMismatch::create(
60266041
*this, lhs, rhs, getConstraintLocator(locator)));
60276042
break;

0 commit comments

Comments
 (0)