-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Related Issues:
- [pigeon] Support
@Sendablein Swift code #140439 - [pigeon] Support Swift Concurrency style api #147283
Use case
Sendable was introduced in Swift 5.5 to ensure thread-safe interactions in concurrent code. With the Swift 6 language mode in Swift 6.0 (Xcode 16), stricter conditions for Sendable conformance are enforced. Although newer Swift compiler can compile in Swift 5 mode, many developers prefer the stricter safety guarantees of Swift 6.
Pigeon, a code generator for Dart and native platform communication, enables seamless cross-platform development. However, the PigeonError class currently does not conform to Sendable, leading to compilation errors in Swift 6 mode and blocking developers from adopting the latest Swift concurrency features.
Example error:
Stored property 'details' of 'Sendable'-conforming class 'PigeonError' has non-sendable type 'Any?'
Proposal
The current PigeonError class is a simple implementation of the Error protocol:
/// Error class for passing custom error details to the Dart side.
final class PigeonError: Error {
let code: String
let message: String?
let details: Any?
init(code: String, message: String?, details: Any?) {
self.code = code
self.message = message
self.details = details
}
var localizedDescription: String {
return "PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>"))"
}
}To make the class compatible with Swift 6.0 mode, I propose changing the details property type from Any? to Sendable?. This ensures the class conforms to Sendable since:
- The
Errorprotocol already conforms toSendable. - All other properties (
StringandOptional) areSendable.
This change introduces backward incompatibility because of the details type change. However, most existing use cases of PigeonError involve small, well-defined payloads, so migration should be straightforward. Developers can update their code by ensuring objects passed to details conform to Sendable.