@@ -10,11 +10,24 @@ func doesEscape(_ fn : @escaping () -> Int) {}
10
10
func takesGenericClosure< T> ( _ a : Int , _ fn : @noescape ( ) -> T ) { } // expected-warning{{@noescape is the default and is deprecated}} {{47-57=}}
11
11
12
12
13
+ func takesArray( _ fns: [ ( ) -> Int ] ) {
14
+ doesEscape ( fns [ 0 ] ) // Okay - array-of-function parameters are escaping
15
+ }
16
+
17
+ func takesVariadic( _ fns: ( ) -> Int ... ) {
18
+ doesEscape ( fns [ 0 ] ) // Okay - variadic-of-function parameters are escaping
19
+ }
20
+
13
21
func takesNoEscapeClosure( _ fn : ( ) -> Int ) {
14
22
// expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
15
23
// expected-note@-2{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
16
24
// expected-note@-3{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
17
25
// expected-note@-4{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
26
+ // expected-note@-5{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
27
+ // expected-note@-6{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
28
+ // expected-note@-7{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
29
+ // expected-note@-8{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
30
+ // expected-note@-9{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }}
18
31
takesNoEscapeClosure { 4 } // ok
19
32
20
33
_ = fn ( ) // ok
@@ -37,6 +50,13 @@ func takesNoEscapeClosure(_ fn : () -> Int) {
37
50
doesEscape ( fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
38
51
takesGenericClosure ( 4 , fn) // ok
39
52
takesGenericClosure ( 4 ) { fn ( ) } // ok.
53
+
54
+ _ = [ fn] // expected-error {{non-escaping parameter 'fn' may only be called}}
55
+ _ = [ doesEscape ( fn) ] // expected-error {{'(() -> Int) -> ()' is not convertible to '(@escaping () -> Int) -> ()'}}
56
+ _ = [ 1 : fn] // expected-error {{non-escaping parameter 'fn' may only be called}}
57
+ _ = [ 1 : doesEscape ( fn) ] // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
58
+ _ = " \( doesEscape ( fn) ) " // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}}
59
+ _ = " \( takesArray ( [ fn] ) ) " // expected-error {{using non-escaping parameter 'fn' in a context expecting an @escaping closure}}
40
60
}
41
61
42
62
class SomeClass {
@@ -340,4 +360,3 @@ func noescapeD_noescapeT(@noescape f: @noescape () -> Bool) {} // expected-error
340
360
341
361
func autoclosureD_noescapeT( @autoclosure f: @noescape ( ) -> Bool ) { } // expected-error {{attribute can only be applied to types, not declarations}}
342
362
// expected-warning@-1{{@noescape is the default and is deprecated}} {{45-55=}}
343
-
0 commit comments