fix <rdar://problem/21553065> Spurious diagnostic: '_' can only appear in a pattern or on the left side of an assignment

... by reimplementing the DiscardAssignmentExpr checker in MiscDiagnostics 
instead of being in CSApply (which gets run on partial expression ASTs).

Also, when type checking and salvaging an expression fails, do not generate 
structural diagnostics in addition to the type checker diagnostics, they are 
just noise.



Swift SVN r29937
This commit is contained in:
Chris Lattner
2015-07-07 05:52:17 +00:00
parent 70ee2adc84
commit acecd187a3
7 changed files with 60 additions and 18 deletions

View File

@@ -5987,14 +5987,10 @@ namespace {
// Track whether we're in the left-hand side of an assignment...
if (auto assign = dyn_cast<AssignExpr>(expr)) {
++LeftSideOfAssignment;
if (auto dest = assign->getDest()->walk(*this))
assign->setDest(dest);
else
return { false, nullptr };
--LeftSideOfAssignment;
auto &cs = Rewriter.getConstraintSystem();
auto srcLocator = cs.getConstraintLocator(
@@ -6009,12 +6005,7 @@ namespace {
expr = Rewriter.visitAssignExpr(assign, srcLocator);
return { false, expr };
}
// ...so we can verify that '_' only appears there.
if (isa<DiscardAssignmentExpr>(expr) && LeftSideOfAssignment == 0)
Rewriter.getConstraintSystem().getTypeChecker()
.diagnose(expr->getLoc(), diag::discard_expr_outside_of_assignment);
Rewriter.walkToExprPre(expr);
return { true, expr };
}