Skip to content

[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

Merged
merged 1 commit into from
Jun 17, 2017

Conversation

itaiferber
Copy link
Contributor

@itaiferber itaiferber commented Jun 14, 2017

What's in this pull request?
Cherry-picks #10249 for swift-4.0-branch. Addresses SR-5089.

  • Explanation: 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.

  • 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.

@itaiferber
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - b676e4063d9c8a3ab72386de502052e37a961633
Test requested by - @itaiferber

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - b676e4063d9c8a3ab72386de502052e37a961633
Test requested by - @itaiferber

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)
@itaiferber
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - b676e4063d9c8a3ab72386de502052e37a961633
Test requested by - @itaiferber

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - b676e4063d9c8a3ab72386de502052e37a961633
Test requested by - @itaiferber

@itaiferber
Copy link
Contributor Author

@swift-ci Please test Linux

@tkremenek tkremenek merged commit 3283efb into swiftlang:swift-4.0-branch Jun 17, 2017
@linqingmo
Copy link
Contributor

@itaiferber

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?

@itaiferber
Copy link
Contributor Author

@linqingmo throws should remain for compatibility with the protocol; the protocol still should have throws for the cases where a decoder might decide to disambiguate between a "regular array/dictionary" and a keyed/unkeyed container. It also needs to be able to throw in case it's parsing data as it decodes — if the data is discovered to be corrupted, it should be able to fail there.

@linqingmo
Copy link
Contributor

@itaiferber Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants