Commit Graph

160 Commits

Author SHA1 Message Date
Slava Pestov
7ec163a83a Parse: Simplify parsing of generic types
Now that preCheckExpression() can handle more cases, we can
eliminate a special case where sometimes we would make
DeclRefExprs instead of TypeExprs for references to generic
types.
2017-05-23 02:10:03 -07:00
Itai Ferber
9988624843 Add explicit support for IUOs
Since implicitly unwrapped optional types do not reflect conformances
added to Optional, we need to explicitly allow and handle them.
2017-05-22 14:05:09 -07:00
Itai Ferber
dd0bf0ee83 Clean up Codable synthesis slightly
Following feedback in https://github.com/apple/swift/pull/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)
2017-05-22 13:21:49 -07:00
Itai Ferber
26d0d5defe Synthesize *IfPresent calls for Optional values
Optional properties now get synthesized encodeIfPresent(...) and
decodeIfPresent(...) calls (to avoid encoding needless information, and
to be more accepting on input).
2017-05-22 12:17:21 -07:00
Itai Ferber
91a8aaa0f4 Prevent synthesis for non-Codable stdlib types
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.
2017-05-22 09:29:36 -07:00
Itai Ferber
5eb58ef8d4 Improve experience of derivation of Codable types
* Introduce diagnostics that explain why derivation of
  Encodable/Decodable fail rather than just silently failing
* Allow properties with default values to be omitted from CodingKeys
  enum and from encoding/decoding
* If `CodingKeys` is a typealias, reach through it more consistently to
  get at the final target type
* Add unit tests to confirm this new behavior for classes and structs

NOTE: Although this made the diff bigger, standalone variables named
"type" have been renamed to "target" throughout, since the word "type"
may be ambiguous and makes debugging impossible. "target" is unique.
2017-05-19 09:45:54 -07:00
practicalswift
fff77b01c7 [gardening] Remove unused variables 2017-05-05 17:03:02 +02:00
Itai Ferber
4c2320724e Fix init(from:) required condition 2017-04-27 12:44:41 -07:00
Itai Ferber
3e6eb8f20a Derive encoding an empty container by default
struct X : Codable {} should generate an encode(to:) which encodes an
empty keyed container, not an encode(to:) which does nothing
2017-04-27 10:56:19 -07:00
Itai Ferber
e2318392be Add CodingKey and *codable derived conformance
* Allow CodingKey conformance to be automatically derived for enums
  which have no raw type (with no associated values) and which have
  a raw type of String or Int.
* Allow Encodable and Decodable conformance to be automatically derived
  for classes and structs with Encodable/Decodable properties
* Add initial unit tests for verifying derived conformance
2017-04-25 13:13:35 -07:00