File tree Expand file tree Collapse file tree 4 files changed +7
-4
lines changed Expand file tree Collapse file tree 4 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -524,7 +524,7 @@ func defer_in_closure_in_generic<T>(_ x: T) {
524
524
// CHECK-LABEL: sil private @$S10statements017defer_in_closure_C8_genericyyxlFyycfU_ : $@convention(thin) <T> () -> ()
525
525
_ = {
526
526
// CHECK-LABEL: sil private @$S10statements017defer_in_closure_C8_genericyyxlFyycfU_6$deferL_yylF : $@convention(thin) <T> () -> ()
527
- defer { generic_callee_1 ( T . self) }
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}}
528
528
}
529
529
}
530
530
@@ -537,7 +537,7 @@ func defer_mutable(_ x: Int) {
537
537
// CHECK: function_ref @$S10statements13defer_mutableyySiF6$deferL_yyF : $@convention(thin) (@inout_aliasable Int) -> ()
538
538
// CHECK-NOT: [[BOX]]
539
539
// CHECK: destroy_value [[BOX]]
540
- defer { _ = x }
540
+ defer { _ = x } // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
541
541
}
542
542
543
543
protocol StaticFooProtocol { static func foo( ) }
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ defer { print(y) } // expected-error {{constant 'y' used in defer before being i
21
21
// Test top-level functions.
22
22
23
23
func testFunc( ) { // expected-error {{variable 'x' used by function definition before being initialized}}
24
- defer { print ( x) }
24
+ defer { print ( x) } // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
25
25
}
26
26
27
27
// Test top-level closures.
Original file line number Diff line number Diff line change @@ -285,7 +285,7 @@ func deferTryNoReturn() throws {
285
285
}
286
286
287
287
func noReturnInDefer( ) {
288
- defer {
288
+ defer { // expected-warning {{'defer' at the end of its scope is redundant and will execute immediately}}{{3-8=do}}
289
289
_ = Lisp ( )
290
290
die ( ) // expected-note {{a call to a never-returning function}}
291
291
die ( ) // expected-warning {{will never be executed}}
Original file line number Diff line number Diff line change @@ -342,14 +342,17 @@ func test_defer(_ a : Int) {
342
342
343
343
// Not ok.
344
344
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
346
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}}
346
348
}
347
349
348
350
class SomeTestClass {
349
351
var x = 42
350
352
351
353
func method( ) {
352
354
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}}
353
356
}
354
357
}
355
358
You can’t perform that action at this time.
0 commit comments