Open
Description
Description
the following code should produce a compile-time error disallowing the use of a non-sendable class across two isolation domains. running the code with TSAN enabled detects a data race at runtime.
Reproduction
class NonSendableClass {
var data: Int = 0
}
func f(_ ns: NonSendableClass) async {
ns.data += 1
}
@MainActor
func main() async {
let nonSendableObject = NonSendableClass()
Task {
await f(nonSendableObject)
}
await Task.yield()
_ = nonSendableObject.data
}
await main()
Expected behavior
the use of nonSendableObject
in this way should produce a compiler error detecting a potential data race.
Environment
swift-driver version: 1.113 Apple Swift version 6.0 (swiftlang-6.0.0.7.6 clang-1600.0.24.1)
Target: arm64-apple-macosx14.0
(Xcode 16, beta 5)
Additional information
originally reported via: https://forums.swift.org/t/a-non-sendable-class-can-bypass-swift6s-concurrency-check-and-cause-data-race.
notes:
- changing to
Task.detached
causes a compiler error to be produced - the 5.10 compiler appeared to produce a warning with complete concurrency checking enabled