Open
Description
Description
The Following code compiles but contains a race the compiler failed to detect:
@MainActor
func test() {
var s = 1
Task { @MainActor in
for _ in 0..<100 {
s += 1
}
}
Task.detached {
for _ in 0..<100 {
s += 1
}
}
}
Reproduction
See above in description.
Expected behavior
s
is being captured into 2 closures with different isolation, that should be invalid.
Environment
- Swift version 6.2-dev (LLVM ac66248b7c45109, Swift 92fd571)
- Target: x86_64-unknown-linux-gnu
- Build config: +assertions
- Internal compiler ID: swiftdevsnapshot
Additional information
This bug may be somewhat related to #76929.
The difference is that, in this bug, a var
is declared in a @MainActor
scope, and later sent into a nonisolated region; while in the referenced one, a var
is declared in a nonisolated scope and later sent into a @MainActor
region.