mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSClosure] Warn about defer being the last element in the closure body
This commit is contained in:
@@ -1246,6 +1246,18 @@ private:
|
||||
ASTNode visitBraceStmt(BraceStmt *braceStmt) {
|
||||
auto &cs = solution.getConstraintSystem();
|
||||
|
||||
// Diagnose defer statement being last one in block.
|
||||
if (!braceStmt->empty()) {
|
||||
if (auto stmt = braceStmt->getLastElement().dyn_cast<Stmt *>()) {
|
||||
if (auto deferStmt = dyn_cast<DeferStmt>(stmt)) {
|
||||
auto &diags = closure->getASTContext().Diags;
|
||||
diags
|
||||
.diagnose(deferStmt->getStartLoc(), diag::defer_stmt_at_block_end)
|
||||
.fixItReplace(deferStmt->getStartLoc(), "do");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &node : braceStmt->getElements()) {
|
||||
if (auto expr = node.dyn_cast<Expr *>()) {
|
||||
// Rewrite the expression.
|
||||
|
||||
Reference in New Issue
Block a user