Skip to content

Commit 7725769

Browse files
committed
[CSSimplify] Don't pile up fixes for incorrect optional chaining
If the contextual type propagated into the optional chain mismatches with the inner type formed from its member references and that inner type is a result of some fix, let's consider that un-salvageable and avoid producing additional "ignore contextual type" fixes which only lead to subpar solutions. (cherry picked from commit 243cc16)
1 parent e9fcd8c commit 7725769

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5425,8 +5425,14 @@ bool ConstraintSystem::repairFailures(
54255425
auto contextualTy = simplifyType(rhs)->getOptionalObjectType();
54265426
if (!lhs->getOptionalObjectType() && !lhs->hasTypeVariable() &&
54275427
contextualTy && !contextualTy->isTypeVariableOrMember()) {
5428-
conversionsOrFixes.push_back(IgnoreContextualType::create(
5429-
*this, lhs, rhs, getConstraintLocator(OEE->getSubExpr())));
5428+
auto *fixLocator = getConstraintLocator(OEE->getSubExpr());
5429+
// If inner expression already has a fix, consider this two-way
5430+
// mismatch as un-salvageable.
5431+
if (hasFixFor(fixLocator))
5432+
return false;
5433+
5434+
conversionsOrFixes.push_back(
5435+
IgnoreContextualType::create(*this, lhs, rhs, fixLocator));
54305436
return true;
54315437
}
54325438
}

0 commit comments

Comments
 (0)