The following code compiles fine without NonIsolatedNonSendingByDefault
protocol Writer {}
public struct Response: Sendable {
let write: @Sendable (inout any Writer) async throws -> Void
init(_ write: @Sendable @escaping (inout any Writer) async throws -> Void) {
self.write = { writer in
try await write(&writer)
}
}
}
When I enable `NonIsolatedNonSendingByDefault` I get the following error
Cannot convert '@Sendable (inout any Writer) async throws -> Void' to 'nonisolated(nonsending) @Sendable (inout any Writer) async throws -> Void' because crossing of an isolation boundary requires parameter and result types to conform to 'Sendable' protocol
It appears to be related to the closure as I can replace the closure with self.write = write and everything works.
In fact if I replace the closure with self.write = { _ in } I get the error again.
Is this expected? And if so is there a way around this?