mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Diagnostics] Don't try to diagnose immutability failures in boolean context
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user