Actor initialisers allow non-sendable types to cross actor boundaries

Why the following code is not rejected? init is non-isolated, so it can be called from any actor. And x belongs the actor, where init was called. But nonSendable belongs to actor self. And initialising nonSendable with x is crossing actor boundaries.

actor SomeActor {
  let nonSendable: NonSendable
  init(_ x: NonSendable) {
    self.nonSendable = x
  }
}

My understanding is that non-sendable properties of an actor can be legacy initialised only by a value was constructed when already isolated on the actor:

actor SomeActor {
  let nonSendable: NonSendable
  init() async {
    // Suspension point must be here
    self.nonSendable = NonSendable()
  }
}

But according to the current rules of the flow-sensitive isolation, switch to the actor happens only after actor is fully-initialised. Effectively this means that actors cannot have stored properties of non-isolated types at all.

1 Like