I'm seeing a difference in isolation checking between accessing a computed property vs invoking a method and I'm not sure if it's correct or not.
Accessing an async
computed property of a non-sendable type in an isolated context (e.g. @MainActor
) produces an error, whereas invoking an async method on the non-sendable type does not:
class NonSendable {
var foo: Int { get async { 42 } }
func foo() async {}
}
@MainActor
func foo() async {
// 🛑 Non-sendable type 'NonSendable' exiting main
// actor-isolated context in call to non-isolated
// property 'foo' cannot cross actor boundary
_ = await NonSendable().foo
// OK ✅
await NonSendable().foo()
}
I would think both should cause failures. It also doesn't fail if you pass NonSendable()
to an async
free function, and I would expect that to fail too.
This happens in Xcode 16 beta 4 as well as a snapshot from 7-16. Haven't tried a newer snapshot yet.