Skip to content

Commit 232185e

Browse files
committed
[Diagnostics] Don't try to diagnose immutability failures in boolean context
1 parent f8afae9 commit 232185e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,13 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
12941294
Expr *diagExpr = getRawAnchor();
12951295
SourceLoc loc = diagExpr->getLoc();
12961296

1297+
auto &cs = getConstraintSystem();
1298+
// Assignment is not allowed inside of a condition,
1299+
// so let's not diagnose immutability, because
1300+
// most likely the problem is related to use of `=` itself.
1301+
if (cs.getContextualTypePurpose() == CTP_Condition)
1302+
return false;
1303+
12971304
if (auto assignExpr = dyn_cast<AssignExpr>(diagExpr)) {
12981305
diagExpr = assignExpr->getDest();
12991306
}

0 commit comments

Comments
 (0)