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.
This commit is contained in:
Itai Ferber
2017-05-18 18:37:12 -07:00
parent a46c48438c
commit 5eb58ef8d4
15 changed files with 571 additions and 270 deletions

View File

@@ -43,13 +43,10 @@ class SimpleChildClass : SimpleClass {
}
}
// These are wrapped in a dummy function to avoid binding a global variable.
func foo() {
// They should receive synthesized init(from:) and an encode(to:).
let _ = SimpleChildClass.init(from:)
let _ = SimpleChildClass.encode(to:)
// They should receive synthesized init(from:) and an encode(to:).
let _ = SimpleChildClass.init(from:)
let _ = SimpleChildClass.encode(to:)
// The synthesized CodingKeys type should not be accessible from outside the
// class.
let _ = SimpleChildClass.CodingKeys.self // expected-error {{'CodingKeys' is inaccessible due to 'private' protection level}}
}
// The synthesized CodingKeys type should not be accessible from outside the
// class.
let _ = SimpleChildClass.CodingKeys.self // expected-error {{'CodingKeys' is inaccessible due to 'private' protection level}}