A few comments:
-
The idiomatic way is to define
act()as a global funciton and apply@Ato it. This should resolves the error inf(). -
The "nonisolated context" in the diagnostic in
g()appears to be a bug unrelated toassumeIsolated. I've filed a bug. -
The issue with
g()can be demonstrated with simpler code. IIUC this is as expected because compiler see the parameter of the closure as an instance ofA, which isn't necessarilyA.share. I think you have to use the solution in this post to get the behavior you wanted.
@globalActor
actor A: GlobalActor {
static let shared: A = .init()
}
@A
class C {
var str = "str"
func g() {
let fn: (isolated A) throws -> Void = { a in
_ = self.str // error: global actor 'A'-isolated property 'str' can not be referenced from a nonisolated context
}
}
}