-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[4.0] Allow SingleValueContainers to decode collections #10261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.0] Allow SingleValueContainers to decode collections #10261
Conversation
@swift-ci Please test |
Build failed |
Build failed |
SingleValueDecondingContainers in JSON and Plist previously held the assertion that attempting to decode an array or dictionary from them was a type mismatch (since those represented unkeyed and keyed containers, respectively). This assertion is no longer true, though, since encode<T : Encodable>(_:) and decode<T : Decodable>(_:) allow you to do just that. This lifts the assertion and adds unit tests to both implementations to ensure this works. (Addresses https://bugs.swift.org/browse/SR-5089)
b676e40
to
0ba863e
Compare
@swift-ci Please test |
Build failed |
Build failed |
@swift-ci Please test Linux |
func singleValueContainer() throws -> SingleValueDecodingContainer It seems throws can be removed, since it will never throw an error. Or it is left here for some reason? |
@linqingmo |
@itaiferber Thanks. |
What's in this pull request?
Cherry-picks #10249 for swift-4.0-branch. Addresses SR-5089.
Explanation:
SingleValueDecondingContainer
s in JSON and Plist previously held the assertion that attempting to decode an array or dictionary from them was a type mismatch (since those represented unkeyed and keyed containers, respectively). This assertion is no longer true, though, sinceencode<T : Encodable>(_:)
anddecode<T : Decodable>(_:)
allow you to do just that.This lifts the assertion and adds unit tests to both implementations to ensure this works.
Scope: Affects those using the new Codable API to encode and decode from a single value container.
Radar: rdar://problem/32567981
Risk: Low
Testing: This adds new unit tests to confirm expected behavior.