mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
One of the limitations of not having conditional conformance at the moment is that the implementation of `init(from:)` and `encode(to:)` on types which require it is that failure to cast dependent types to `Encodable` or `Decodable` is a runtime failure. There is no way to statically guarantee that the wrapped type is `Encodable` or `Decodable`. As such, in those implementations, at best we can directly call `(element as! Encodable).encode(to: encoder)`, or similar. However, this encodes the element directly into an encoder, without giving the encoder a chance to intercept the type. This is problematic for `JSONEncoder` because it cannot apply a strategy if it doesn't get to intercept the type. This gives a temporary workaround for JSON strategies because of internal Foundation knowledge.
14 KiB
14 KiB