mbrandonw
(Brandon Williams)
1
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.
vns
2
I think this actually shouldn't raise an error for the property in that example. Due to the region-based isolation, NonSendable in your example is in disconnected region, so it is safe to pass it to another isolation via async call. I think there was a thread on false diagnostic for computed properties...
UPD. That one: https://forums.swift.org/t/why-does-sending-a-sendable-value-risk-causing-data-races