Open
Description
Description
If we have a non-isolated class with a method that creates a task whose closure is isolated to, say, the main actor, capturing a main actor isolated instance method in the capture list does not produce any data race warnings or errors.
Reproduction
class Bar {
@MainActor func mainActorMethod() {}
}
class Foo {
let bar = Bar()
init() {
self.start()
}
func start() {
Task { @MainActor [callBar] in
callBar()
}
}
@MainActor func callBar() {
self.bar.mainActorMethod()
}
}
Foo()
Expected behavior
I expect a compiler error mentioning risks causing data races.
Environment
Swift 6 and 6.2
Additional information
Additional variations that don't produce any errors are posted in
https://forums.swift.org/t/why-no-data-race-warning-with-task-capturing-isolated-instance-method/80952
under Keith Bauer's comment.
It may be the case that this has been resolved according to some of the comments.