Commit Graph

16 Commits

Author SHA1 Message Date
Slava Pestov
d8c5e798d5 Sema: Fix incorrect usage of NormalProtocolConformance in Codable synthesis
Noticed by inspection. It looks like there are no tests for generic
Codable types. I'm just adding one to cover the changed code path.
2017-11-04 23:40:24 -07:00
Itai Ferber
f90827e17b Codable: excluded vars shouldn’t need explicit val
Properties of Codable types which are optional and excluded via the CodingKeys enum should not require an explicit nil assignment, since in all other cases, optional vars get a default value of nil.
2017-09-11 10:29:07 -07:00
Ewa Matejska
21b2073b9e Small update to diagnostics to avoid the word yet 2017-09-07 10:34:34 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Itai Ferber
071caf263a Additional responses to feedback
* Make Decodable synthesis lazy again
* Remove side effects from assertions
* Assert on superclass failable initializers (and verify via a unit test)
* Fix space typo
* Remove more needless instances of single-element arrays
* Unambiguously refer to init() in unit tests
* Add failable superclass init tests and a test to ensure Decodable fails to be inherited when superclass synthesis fails
* Add tests for structs to ensure they receive no-argument initializers where appropriate
2017-07-24 08:02:19 -07:00
Itai Ferber
a30e9117e6 Responses to feedback
* Use `isSpecificProtocol` instead of `==`
* Synthesize Encodable implementation lazily
* Don’t mark conformances as Used when they don’t need to be
* Avoid creating explicit one-element arrays
* Use lookupDirect instead of walking AST manually
* Produce diagnostic for Decodable classes whose non-Decodable superclass has a failable init
* Filter lazy vars manually since getStoredProperties() does not always do so
* Amend Decodable class diagnostic text
* Check for enum RawType errors only if the type was already validated
* Update unit tests to match changes
2017-07-20 08:06:21 -07:00
Itai Ferber
f873f5ec41 Add notes to suggest overriding init(from:)
Classes which inherit from Codable classes inherit their Codable implementation (as opposed to synthesizing their own). In cases where they add their own storage, they will fail to inherit their superclass’s init(from:). In this case, we provide a diagnostic suggesting that init(from:) be overridden.
2017-07-20 07:55:09 -07:00
Itai Ferber
eb031e8c86 Don’t prevent default/memberwise init
Some synthesized initializers (specifically, init(from:)) should not prevent the synthesis of a default or memberwise initializer.
2017-07-20 07:55:09 -07:00
Itai Ferber
1f8f1fea50 Allow overriding synthesized Decodable impl.
Classes which receive a synthesized Decodable implementation should be able to subclass non-Decodable classes (if the superclass has an accessible init()) method.

Also improve diagnostics when this is not the case.
2017-07-20 07:55:09 -07:00
Itai Ferber
e86428559a Expose synthesized members in AST lookups
Some types and members are synthesized by derived protocol conformances
(e.g. the CodingKeys member type or init(from:)/encode(to:) members
from Decodable/Encodable conformance) — however, they are not visible
in AST lookup if they have not been synthesized.

Exposes a LazyResolver callback for performing member synthesis where
relevant during qualified lookups to synthesize these members on demand
when needed.
2017-07-13 13:27:08 -07:00
Itai Ferber
1c020fcae7 Add unit test to confirm ordering of Codable diags 2017-06-20 14:29:59 -07:00
Itai Ferber
238a7a281e Allow synthesis of Codable for weak/unowned vars
The type of non-strong properties is wrapped in a ReferenceStorageType,
which does not conform to Codable. This needs to be unwrapped so the
inner reference type can be considered for Codable conformance.
2017-06-16 10:42:27 -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
Itai Ferber
22185d237f CodingKey/*Codable tests don't need ObjC interop
Since all of the core types are now in the Swift stdlib, the tests no
longer rely on objc_interop or Foundation.
2017-04-25 14:11:24 -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