Skip to content

Commit e58dfa9

Browse files
[test] Add regression tests for SR-14720
1 parent 48792bb commit e58dfa9

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

test/attr/attr_escaping.swift

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,14 @@ func takesNoEscapeFunction(fn: () -> ()) { // expected-note {{parameter 'fn' is
146146

147147

148148
class FooClass {
149-
var stored : Optional<(()->Int)->Void> = nil
149+
var stored : Optional<(()->Int)->Void> = nil // expected-note {{add explicit @escaping to function parameter #0}} {{26-26=@escaping }}
150150
var computed : (()->Int)->Void {
151151
get { return stored! }
152152
set(newValue) { stored = newValue } // ok
153153
}
154154
var computedEscaping : (@escaping ()->Int)->Void {
155155
get { return stored! }
156-
set(newValue) { stored = newValue } // expected-error{{assigning non-escaping parameter 'newValue' to an @escaping closure}}
157-
// expected-note@-1 {{parameter 'newValue' is implicitly non-escaping}}
156+
set(newValue) { stored = newValue } // expected-error{{converting escaping to non-escaping functions of type '() -> Int' in parameter position #0 of function type member 'stored' is not allowed}}
158157
}
159158
}
160159

@@ -230,3 +229,29 @@ extension SR_9760 {
230229

231230
// SR-9178
232231
func foo<T>(_ x: @escaping T) {} // expected-error 1{{@escaping attribute only applies to function types}}
232+
233+
// SR-14720
234+
class SR14720 {
235+
let ok: (@escaping () -> Void) -> Void // OK
236+
let callback: (() -> Void) -> Void // expected-note {{add explicit @escaping to function parameter #0}} {{18-18=@escaping }}
237+
let callback1: (() -> Void, () -> Void) -> Void // expected-note {{add explicit @escaping to function parameter #1}} {{31-31=@escaping }}
238+
let callbackAuto: (@autoclosure () -> Void) -> Void // expected-note {{add explicit @escaping to function parameter #0}} {{34-34= @escaping}}
239+
let callbackOpt: ((() -> Void) -> Void)? // expected-note{{add explicit @escaping to function parameter #0}} {{22-22=@escaping }}
240+
241+
init(f: @escaping (@escaping() -> Void) -> Void) {
242+
self.callback = f // expected-error{{converting escaping to non-escaping functions of type '() -> Void' in parameter position #0 of function type member 'callback' is not allowed}}
243+
self.ok = f // Ok
244+
}
245+
246+
init(af: @escaping (@escaping() -> Void) -> Void) {
247+
self.callbackOpt = af // expected-error{{converting escaping to non-escaping functions of type '() -> Void' in parameter position #0 of function type member 'callbackOpt' is not allowed}}
248+
}
249+
250+
init(a: @escaping (@escaping () -> Void) -> Void) {
251+
self.callbackAuto = a // expected-error{{converting escaping to non-escaping functions of type '() -> Void' in parameter position #0 of function type member 'callbackAuto' is not allowed}}
252+
}
253+
254+
init(f: @escaping (() -> Void, @escaping() -> Void) -> Void) {
255+
self.callback1 = f // expected-error{{converting escaping to non-escaping functions of type '() -> Void' in parameter position #1 of function type member 'callback1' is not allowed}}
256+
}
257+
}

0 commit comments

Comments
 (0)