Closed
Description
Description
The compiler allows to set an @isolated(any)
closure to a property that is not isolated itself. Shouldn't this throw a compilation error?
struct Example {
var getString: @Sendable () -> String
init(getString: @isolated(any) @escaping @Sendable () -> String) {
self.getString = getString
}
}
Reproduction
struct Example {
var getString: @Sendable () -> String
init(getString: @isolated(any) @escaping @Sendable () -> String) {
self.getString = getString
}
}
await Task.detached {
let e = Example { @MainActor in
MainActor.assertIsolated() // This crashes
return "Hello, world!"
}
print(e.getString())
}.value
Expected behavior
The compiler should not allow self.getString = getString
, unless var getString: @Sendable () -> String
is changed to var getString: @isolated(any) @Sendable () -> String
.
Environment
swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0
Additional information
No response