Non-sendable @MainActor-isolated closure after SE-0434

I've tried enabling GlobalActorIsolatedTypesUsability for our project, and got an unexpected failure in unit tests that use GitHub - nalexn/ViewInspector: Runtime introspection and unit testing of SwiftUI views to inspect some SwiftUI views.

Code inside tries to obtain a closure from a SwiftUI.Button, and cast it to type defined as typealias Callback = @MainActor () -> Void. There is no @Sendable in code, but with GlobalActorIsolatedTypesUsability enabled, it get's compiled as @MainActor @Sendable () -> Void. And closure obtained from SwiftUI has type @MainActor () -> Void, which apparently is a different type with a different metatype instance. So this dynamic cast fails, failing the test.

With GlobalActorIsolatedTypesUsability enabled, is there a way to spell non-@Sendable @MainActor-isolated closure?

EDIT: Wrong feature flag. It is SE-0434/GlobalActorIsolatedTypesUsability, not SE-0418/InferSendableFromCaptures.

1 Like