Skip to content

Commit ffd1366

Browse files
committed
addressing comments on PR
- moving WARNING definition from DiagnosticsCommon.def to DiagnosticsSema.def - improving WARNING message to better align with guidelines described in docs/Diagnostics.md as suggested by @xwu. - adapting expected warning message in tests.
1 parent 783ab96 commit ffd1366

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ NOTE(previous_decldef,none,
5454
NOTE(brace_stmt_suggest_do,none,
5555
"did you mean to use a 'do' statement?", ())
5656

57-
WARNING(defer_stmt_at_block_end,none,
58-
"'defer' at the end of its scope is redundant and will execute immediately; "
59-
"replace it with 'do'", ())
60-
6157
// Generic disambiguation
6258
NOTE(while_parsing_as_left_angle_bracket,none,
6359
"while parsing this '<' as a type parameter bracket", ())

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,10 @@ ERROR(jump_out_of_defer,none,
30333033
"'%0' cannot transfer control out of a defer statement",
30343034
(StringRef))
30353035

3036+
WARNING(defer_stmt_at_block_end,none,
3037+
"'defer' statement before end of scope always executes immediately; "
3038+
"replace with 'do' statement to silence this warning", ())
3039+
30363040
ERROR(return_invalid_outside_func,none,
30373041
"return invalid outside of a func", ())
30383042

test/SILGen/statements.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func defer_in_closure_in_generic<T>(_ x: T) {
524524
// CHECK-LABEL: sil private @$S10statements017defer_in_closure_C8_genericyyxlFyycfU_ : $@convention(thin) <T> () -> ()
525525
_ = {
526526
// CHECK-LABEL: sil private @$S10statements017defer_in_closure_C8_genericyyxlFyycfU_6$deferL_yylF : $@convention(thin) <T> () -> ()
527-
defer { generic_callee_1(T.self) } // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{5-10=do}}
527+
defer { generic_callee_1(T.self) } // expected-warning {{'defer' statement before end of scope always executes immediately}}{{5-10=do}}
528528
}
529529
}
530530

@@ -537,7 +537,7 @@ func defer_mutable(_ x: Int) {
537537
// CHECK: function_ref @$S10statements13defer_mutableyySiF6$deferL_yyF : $@convention(thin) (@inout_aliasable Int) -> ()
538538
// CHECK-NOT: [[BOX]]
539539
// CHECK: destroy_value [[BOX]]
540-
defer { _ = x } // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
540+
defer { _ = x } // expected-warning {{'defer' statement before end of scope always executes immediately}}{{3-8=do}}
541541
}
542542

543543
protocol StaticFooProtocol { static func foo() }

test/SILOptimizer/definite_init_diagnostics_globals.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defer { print(y) } // expected-error {{constant 'y' used in defer before being i
2121
// Test top-level functions.
2222

2323
func testFunc() { // expected-error {{variable 'x' used by function definition before being initialized}}
24-
defer { print(x) } // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
24+
defer { print(x) } // expected-warning {{'defer' statement before end of scope always executes immediately}}{{3-8=do}}
2525
}
2626

2727
// Test top-level closures.

test/SILOptimizer/unreachable_code.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func deferTryNoReturn() throws {
285285
}
286286

287287
func noReturnInDefer() {
288-
defer { // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
288+
defer { // expected-warning {{'defer' statement before end of scope always executes immediately}}{{3-8=do}}
289289
_ = Lisp()
290290
die() // expected-note {{a call to a never-returning function}}
291291
die() // expected-warning {{will never be executed}}

test/Sema/diag_defer_block_end.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
let x = 1
44
let y = 2
55
if (x > y) {
6-
defer { // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{5-10=do}}
6+
defer { // expected-warning {{'defer' statement before end of scope always executes immediately}}{{5-10=do}}
77
print("not so useful defer stmt.")
88
}
99
}
1010

1111
func sr7307(_ value: Bool) {
1212
let negated = !value
13-
defer { // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{5-10=do}}
13+
defer { // expected-warning {{'defer' statement before end of scope always executes immediately}}{{5-10=do}}
1414
print("negated value is {negated}")
1515
}
1616
}

test/stmt/statements.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,17 @@ func test_defer(_ a : Int) {
342342

343343
// Not ok.
344344
while false { defer { break } } // expected-error {{'break' cannot transfer control out of a defer statement}}
345-
// expected-warning@-1 {{'defer' at the end of its scope is redundant and will execute immediately}}{{17-22=do}}
345+
// expected-warning@-1 {{'defer' statement before end of scope always executes immediately}}{{17-22=do}}
346346
defer { return } // expected-error {{'return' cannot transfer control out of a defer statement}}
347-
// expected-warning@-1 {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
347+
// expected-warning@-1 {{'defer' statement before end of scope always executes immediately}}{{3-8=do}}
348348
}
349349

350350
class SomeTestClass {
351351
var x = 42
352352

353353
func method() {
354354
defer { x = 97 } // self. not required here!
355-
// expected-warning@-1 {{'defer' at the end of its scope is redundant and will execute immediately}}{{5-10=do}}
355+
// expected-warning@-1 {{'defer' statement before end of scope always executes immediately}}{{5-10=do}}
356356
}
357357
}
358358

test/stmt/yield.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func call_yield() {
8282
struct YieldInDefer {
8383
var property: String {
8484
_read {
85-
defer {
85+
defer { // expectd-warning {{'defer' statement before end of scope always executes immediately}}{{7-12=do}}
8686
// FIXME: this recovery is terrible
8787
yield ""
8888
// expected-error@-1 {{expression resolves to an unused function}}

0 commit comments

Comments
 (0)