@@ -175,3 +175,38 @@ func passNonThrowingToThrowingAC(_ fn: @autoclosure () -> Int) {
175
175
func passThrowingToThrowingAC( _ fn: @autoclosure ( ) throws -> Int ) {
176
176
takesThrowingAutoclosure ( fn)
177
177
}
178
+
179
+ // rdar://problem/20591571 - Various type inference problems with @autoclosure
180
+ func rdar_20591571( ) {
181
+ func foo( _ g: @autoclosure ( ) -> Int ) {
182
+ typealias G = ( ) -> Int
183
+ let _ = unsafeBitCast ( g, to: G . self) // expected-error {{converting non-escaping value to 'T' may allow it to escape}}
184
+ }
185
+
186
+ func id< T> ( _: T ) -> T { }
187
+ func same< T> ( _: T , _: T ) { }
188
+
189
+ func takesAnAutoclosure( _ fn: @autoclosure ( ) -> Int , _ efn: @escaping @autoclosure ( ) -> Int ) {
190
+ // expected-note@-1 2{{parameter 'fn' is implicitly non-escaping}}
191
+
192
+ var _ = fn // expected-error {{non-escaping parameter 'fn' may only be called}}
193
+ let _ = fn // expected-error {{non-escaping parameter 'fn' may only be called}}
194
+
195
+ var _ = efn
196
+ let _ = efn
197
+
198
+ _ = id ( fn) // expected-error {{converting non-escaping value to 'T' may allow it to escape}}
199
+ _ = same ( fn, { 3 } ) // expected-error {{converting non-escaping value to 'T' may allow it to escape}}
200
+ _ = same ( { 3 } , fn) // expected-error {{converting non-escaping value to 'T' may allow it to escape}}
201
+
202
+ withoutActuallyEscaping ( fn) { _ in } // Ok
203
+ withoutActuallyEscaping ( fn) { ( _: ( ) -> Int ) in } // Ok
204
+ }
205
+ }
206
+
207
+ // rdar://problem/30906031 - [SR-4188]: withoutActuallyEscaping doesn't accept an @autoclosure argument
208
+ func rdar_30906031( in arr: [ Int ] , fn: @autoclosure ( ) -> Int ) -> Bool {
209
+ return withoutActuallyEscaping ( fn) { escapableF in // Ok
210
+ arr. lazy. filter { $0 >= escapableF ( ) } . isEmpty
211
+ }
212
+ }
0 commit comments