Skip to content

Commit 243cc16

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.
1 parent d7a0628 commit 243cc16

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
@@ -5424,8 +5424,14 @@ bool ConstraintSystem::repairFailures(
54245424
auto contextualTy = simplifyType(rhs)->getOptionalObjectType();
54255425
if (!lhs->getOptionalObjectType() && !lhs->hasTypeVariable() &&
54265426
contextualTy && !contextualTy->isTypeVariableOrMember()) {
5427-
conversionsOrFixes.push_back(IgnoreContextualType::create(
5428-
*this, lhs, rhs, getConstraintLocator(OEE->getSubExpr())));
5427+
auto *fixLocator = getConstraintLocator(OEE->getSubExpr());
5428+
// If inner expression already has a fix, consider this two-way
5429+
// mismatch as un-salvageable.
5430+
if (hasFixFor(fixLocator))
5431+
return false;
5432+
5433+
conversionsOrFixes.push_back(
5434+
IgnoreContextualType::create(*this, lhs, rhs, fixLocator));
54295435
return true;
54305436
}
54315437
}

0 commit comments

Comments
 (0)