This code produces an error, as expected:
open class NotSendable {
var value = ""
func runAsync() async {
for i in 0... {
value = "\(i)"
}
}
}
@MainActor
class C {
let x = NotSendable()
func f() async {
await x.runAsync()
// |- error: sending 'self.x' risks causing data races
// `- note: sending main actor-isolated 'self.x' to nonisolated
// instance method 'runAsync()' risks causing data races
// between nonisolated and main actor-isolated uses
}
}
await C().f()
I thought that with SE-0461's -enable-upcoming-feature NonisolatedNonsendingByDefault
, this error should go away, because runAsync
will be run on the main actor, without sending x
. However, I still get the error. Is that expected? If it is, maybe the error should be reworded, since the function is nonisolated(nonsending)
, it's strange to get an error about sending
when calling it. Or is this just a bug in the current implementation, the code safe, and the error spurious? (@hborla)