Open
Description
Description
Using a workaround @jamieQ found (see https://forums.swift.org/t/taskgroup-and-sending-closures/77700/2), I'm able to successfully compile code which has data race.
Reproduction
class NonSendable {}
@MainActor func transferToMainActor(_ x: NonSendable) async { }
func nonIsolatedCallee(_ x: NonSendable) async { }
func nonIsolatedCaller(_ x: NonSendable) async {
await nonIsolatedCallee(x) // this is ok (as expected)
let box = { return x }
await transferToMainActor(box()) // this should fail but it compiles
await nonIsolatedCallee(x) // x is accessed concurrently in both MainActor and global executor.
}
The code is based on an example in "Task Isolated Regions" section in SE-0414. It has data race but it compiles.
Expected behavior
It shouldn't compile
Environment
% swift --version
Apple Swift version 6.0.1 (swift-6.0.1-RELEASE)
Target: arm64-apple-macosx14.0
Additional information
No response