@isolated(any) isolation property is nil for non global actor isolation

You've hit a weirdness in how isolation inference works.

This is "expected", but it can be pretty confusing and it's come up in debate a few times if we should fix the behavior to be what you expected -- since the closure was formed in the actor, and is not sendable etc, it should be isolated to that actor right?

Well, today, that's not how it works... The closure gets the isolation from "an isolated value it closes over", so... since the closure is empty, it does not close over any state and therefore was inferred to be nonisolated.

To get the behavior you expected you have to close over the self:

    func onSelfActor() async {
        print(#isolation) // Shop
        printIsolationName {
            _ = self
        }
    }

Which prints

test.Shop
Optional(test.Shop)

So yes, this is very susprising and may be worth revisiting, but for better or worse this is how it works today.

As recently as a few hours ago during a proposal review we're again debating what to do about this behavior actually, see over here: [Returned for revision] SE-0472: Starting tasks synchronously from caller context - #2 by John_McCall

6 Likes