I've found a problem with down casting, but it is not specific to global-actor isolated conformances, but rather a general problem with marker protocols:
Normally it is not possible to cast to Sendable:
print(x as? Sendable) // error: marker protocol 'Sendable' cannot be used in a conditional cast
But if you ask nicely, it becomes possible:
func castPlease<T>(_ x: Any, to: T.Type) -> T? {
return x as? T
}
protocol P {
func foo()
}
@MainActor
class MA: @MainActor P {
func foo() {}
}
class NS {}
@MainActor
func test() {
print(ObjectIdentifier((any P).self))
print(ObjectIdentifier((any P & Sendable).self))
print(castPlease(MA(), to: (any P & Sendable).self))
print(ObjectIdentifier(Any.self))
print(ObjectIdentifier((any Sendable).self))
print(castPlease(NS(), to: (any Sendable).self))
}
// Prints:
// ObjectIdentifier(0x000000010456d340)
// ObjectIdentifier(0x000000010456d340)
// Optional(foo.MA)
// ObjectIdentifier(0x0000000104529de0)
// ObjectIdentifier(0x0000000104529de0)
// Optional(foo.NS)
Since metatypes with and without Sendable look the same in the runtime, this cannot be solved within the scope of the global-actor isolated conformances. I guess this could be solved by introducing another marker protocol (e.g. Castable), but that is out of scope of this feature.