Files
swift-mirror/test/Unsafe/unsafe_withoutactuallyescaping.swift
Doug Gregor 4742d2c5db [SE-0458] withoutActuallyEscaping is unsafe for @convention(block)
The implementation of `withoutActuallyEscaping` for `@convention(block)`
functions cannot verify at runtime that the function did not actually
escape. Diagnose this as unsafe code under strict memory safety checking.

Fixes rdar://139994149.
2025-03-18 13:26:47 -07:00

20 lines
638 B
Swift

// RUN: %target-typecheck-verify-swift -strict-memory-safety
// REQUIRES: objc_interop
func callMe(body: @escaping @convention(block) () -> Void) { }
func callMeSwiftly(body: @escaping () -> Void) { }
func testCall(body: @convention(block) () -> Void, swiftBody: () -> Void) {
// expected-warning@+2{{unsafe}}{{3-3=unsafe }}
// expected-note@+1{{'withoutActuallyEscaping' function of type '@convention(block) () -> Void' is unsafe}}
withoutActuallyEscaping(body) { nonescapingBody in
callMe(body: nonescapingBody)
}
withoutActuallyEscaping(swiftBody) { nonescapingBody in
callMeSwiftly(body: nonescapingBody)
}
}