File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -1246,6 +1246,18 @@ class ClosureConstraintApplication
12461246 ASTNode visitBraceStmt (BraceStmt *braceStmt) {
12471247 auto &cs = solution.getConstraintSystem ();
12481248
1249+ // Diagnose defer statement being last one in block.
1250+ if (!braceStmt->empty ()) {
1251+ if (auto stmt = braceStmt->getLastElement ().dyn_cast <Stmt *>()) {
1252+ if (auto deferStmt = dyn_cast<DeferStmt>(stmt)) {
1253+ auto &diags = closure->getASTContext ().Diags ;
1254+ diags
1255+ .diagnose (deferStmt->getStartLoc (), diag::defer_stmt_at_block_end)
1256+ .fixItReplace (deferStmt->getStartLoc (), " do" );
1257+ }
1258+ }
1259+ }
1260+
12491261 for (auto &node : braceStmt->getElements ()) {
12501262 if (auto expr = node.dyn_cast <Expr *>()) {
12511263 // Rewrite the expression.
You can’t perform that action at this time.
0 commit comments