[Diagnostics] Don't try to diagnose immutability failures in boolean context

This commit is contained in:
Pavel Yaskevich
2019-09-20 13:32:14 -07:00
parent f8afae9444
commit 232185ec72

View File

@@ -1294,6 +1294,13 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
Expr *diagExpr = getRawAnchor();
SourceLoc loc = diagExpr->getLoc();
auto &cs = getConstraintSystem();
// Assignment is not allowed inside of a condition,
// so let's not diagnose immutability, because
// most likely the problem is related to use of `=` itself.
if (cs.getContextualTypePurpose() == CTP_Condition)
return false;
if (auto assignExpr = dyn_cast<AssignExpr>(diagExpr)) {
diagExpr = assignExpr->getDest();
}