Skip to content

Conversation

@itaiferber
Copy link
Contributor

What's in this pull request?
Cherry-pick the changes in #9791.

Explanation:

  • Adds conformance of Optional to Codable
  • encode(...) arguments are no longer Optional; Optional values go through generic version
  • encodeIfPresent added to KeyedEncodingContainerProtocol to mirror decodeIfPresent
  • Optional values synthesize encodeIfPresent(...) and decodeIfPresent(...) calls instead of encode(...) and decode(...)
  • encodeNil() and decodeNil() added as proper primitives on SingleValueEncodingContainer and SingleValueDecodingContainer, as well as encode<T : Encodable>(_: T) and decode<T : Decodable>(_: T) throws -> T
  • JSONEncoder and PropertyListEncoder updated to reflect these changes

Scope: Important for usage and implementation of the new Codable APIs.
Risk: Low
Radar(s): rdar://problem/32022999, rdar://problem/32023143
Testing: This change updates unit tests to test for expected behavior.

Itai Ferber added 6 commits May 23, 2017 07:19
* Adds conformance of Optional to Codable
* encode(...) arguments are no longer Optional; Optional values go
  through generic version
* encodeIfPresent added to KeyedEncodingContainerProtocol to mirror
  decodeIfPresent
* JSONEncoder and PropertyListEncoder updated to reflect these changes
Optional, Array, Set, and Dictionary currently all conform to Codable
regardless of the type they are generic on. Until conditional
conformance lands and we can rely on their conditional conformance, we
want to prevent Codable derived conformance if a type contains a
property of one of these types when we know it's actually going to fail
at runtime.
Optional properties now get synthesized encodeIfPresent(...) and
decodeIfPresent(...) calls (to avoid encoding needless information, and
to be more accepting on input).
Following feedback in swiftlang#9758:
* Use a struct type for the result of hasValidCodingKeysEnum
* Use an enum type for the result of
* Skip fetching a canonical type before calling getAnyNominal()
  (getAnyNominal() looks through sugar already)
* No need to cast to IterableDeclContext (or DeclContext, even)
Since implicitly unwrapped optional types do not reflect conformances
added to Optional, we need to explicitly allow and handle them.
@itaiferber
Copy link
Contributor Author

@swift-ci Please test

@tkremenek
Copy link
Member

@swift-ci test macOS

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.

2 participants