Skip to content

Commit 466ddcb

Browse files
committed
Adding a fix-it to diagnosting to replace 'defer' with a 'do' statement.
1 parent 03fff5d commit 466ddcb

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ NOTE(brace_stmt_suggest_do,none,
5555
"did you mean to use a 'do' statement?", ())
5656

5757
NOTE(defer_stmt_at_block_end,none,
58-
"'defer' at the end of its scope is redundant and will execute immediately", ())
58+
"'defer' at the end of its scope is redundant and will execute immediately; "
59+
"replace it with 'do'", ())
5960

6061
// Generic disambiguation
6162
NOTE(while_parsing_as_left_angle_bracket,none,

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,8 @@ Stmt *StmtChecker::visitBraceStmt(BraceStmt *BS) {
14121412
if (auto stmt =
14131413
BS->getElement(BS->getNumElements() - 1).dyn_cast<Stmt *>()) {
14141414
if (auto deferStmt = dyn_cast<DeferStmt>(stmt)) {
1415-
TC.diagnose(deferStmt->getStartLoc(), diag::defer_stmt_at_block_end);
1415+
TC.diagnose(deferStmt->getStartLoc(), diag::defer_stmt_at_block_end)
1416+
.fixItReplace(deferStmt->getStartLoc(), "do");
14161417
}
14171418
}
14181419
}

0 commit comments

Comments
 (0)