Global actor isolated methods safety hole.
Description
I've posted a related feedback on the forum, please check this: https://forums.swift.org/t/a-concurrency-safety-hole-related-to-global-actor-isolated-methods/78803.
Reproduction
class A {
func a() async {
await b() // <- ❗️❗️❗️ no compiler errors, not as expected
}
@MainActor
func b() async { }
}
Expected behavior
There should be diagnostics on the line await b(). We had it with compiler 5.10, but not any more nowadays (both with Swift 6.0 and nightly).
Environment
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx14.0
Additional information
No response
AFAIK, it works as expected. Swift will automatically switch to the appropriate actor. You can test with the following program:
@main
struct Main {
static func main() async throws {
await A().a()
}
}
class A {
func a() async {
await b()
}
@MainActor
func b() async {
_ = {print(Thread.current.isMainThread)}()
}
}
It always prints true
AFAIK, it works as expected. Swift will automatically switch to the appropriate actor. You can test with the following program:
The issue is not about where b is executed, the issue it that it is not safe to send self (an A, which is not Sendable) across domains.
As illustrated in the swift forums post in OP, missing such diagnostics could introduce real world concurrency safety problems.
This issue still exists at the moment, hope the fix can make it to Swift 6.2.