Skip to content

Commit 2c245b3

Browse files
committed
[TypeChecker] NFC: Add a couple of test-cases related to rdar://problem/20591571
1 parent 2ad754d commit 2c245b3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/attr/attr_autoclosure.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,31 @@ func passNonThrowingToThrowingAC(_ fn: @autoclosure () -> Int) {
175175
func passThrowingToThrowingAC(_ fn: @autoclosure () throws -> Int) {
176176
takesThrowingAutoclosure(fn)
177177
}
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+
}

0 commit comments

Comments
 (0)