File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -175,3 +175,31 @@ 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
+ }
You can’t perform that action at this time.
0 commit comments