IIUC, the @Sendable annotation on the parameter effectively means the closure will be inferred to be nonisolated in this case. @isolated(any) doesn't affect inference rules, it just allows storing the inferred isolation within the function reference. if you want to get the 'inherit the surrounding actor context' behavior on a @Sendable or sending closure parameter, you'll need to resort to using the unformalized @_inheritActorContext attribute. this thread has some more info on the distinction between these attributes. if you add the underscored attribute, i think the isolation inference will be more like what you expect (godbolt example here).
the attribute won't necessarily cause that behavior, but in the specific given example it will have that effect. if, for example, you wanted the closure passed as the cl parameter to be isolated to a particular global actor, then the inclusion of @Sendable on the closure parameter would no longer cause the parameter to be inferred as nonisolated, e.g.
@MainActor
func f() async {
let main = #isolation
print("inside f: \(main)")
await foo { @MainActor in // closure param in `foo()` will now be main-actor-isolated
let act = #isolation
print("inside cl: \(act)")
}
}
sorry, i'm not entirely clear what you're asking about precisely. what aspects of @Sendable are you wondering about?
so, If I add @MainActor in the closure, it will run on MainActor. Which I know it will. But without adding it, it will run on nonisolated by default, right?