[swift-users] Array<T> not Encodable - error at runtime, not compile time?

Robert Nikander robert.nikander at icloud.com
Thu Oct 26 12:04:28 CDT 2017


Makes sense. Thanks!

> On Oct 26, 2017, at 1:01 PM, Itai Ferber <iferber at apple.com> wrote:
> 
> Hi Robert,
> 
> When the conditional conformance feature arrives in Swift, it will allow us to express extension Array : Encodable where Element : Encodable and extension Array : Decodable where Element : Decodable.
> At the moment, this isn’t possible, so Array is unconditionally Codable and the failure happens at runtime. This will be a compile-time error in a future version of Swift.
> 
> — Itai
> 
> On 26 Oct 2017, at 9:47, Robert Nikander via swift-users wrote:
> 
> Hi,
> 
> This error makes perfect sense, but I’m surprised it's a runtime error. I expected it at compile time. Am I doing something wrong? Is this on the type system to-do list?
> 
> let c = JSONEncoder()
> struct Foo { … }
> let fs: [Foo] = [ Foo(...) ]
> let data = try! c.encode(fs) // Didn’t think this would compile
> 
> The runtime error is: fatal error: Array<Foo> does not conform to Encodable because Foo does not conform to Encodable.
> 
> Rob_______________________________________________
> swift-users mailing list
> swift-users at swift.org <mailto:swift-users at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users <https://lists.swift.org/mailman/listinfo/swift-users>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171026/1f1561ce/attachment.html>


More information about the swift-users mailing list