Commit Graph

172 Commits

Author SHA1 Message Date
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
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
3d4bef7ec4 Stylistic cleanup 2017-07-20 07:55:09 -07:00
Slava Pestov
737174fe9f AST: Add a DeclContext field to ComponentIdentTypeRepr
Plumb this through and set it appropriately, but don't use it
for anything yet.
2017-07-18 22:10:33 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Itai Ferber
c277aa16b5 Merge pull request #10321 from itaiferber/weak-unowned-codable-conformance
Allow synthesis of Codable for weak/unowned vars
2017-06-16 14:19:52 -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
5d663e7cf3 Indentation + style fixes 2017-06-14 13:34:21 -07:00
Itai Ferber
ea5f4e03ce Collate Codable diagnostics for correct ordering
Codable failures produced diagnostics and notes explaining what failed
during decode. These diagnostics were being output as they were
generated, which was suboptimal because it meant that NOTEs could be
produced before the error they were related to.

This was bad for consumers like Xcode, which associate NOTEs with the
last error or warning diagnostic.

This collates these notes using a diagnostic transaction and only
outputs the errors if something goes wrong.
2017-06-14 13:34:21 -07:00
Jordan Rose
4468ad2028 [Sema] Preparations for removal of getName on ValueDecl (#9972)
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 22:36:39 -07:00
Slava Pestov
b3a6b852fc Merge pull request #9870 from slavapestov/unbound-generic-type-cleanup
Sema: Refactoring unbound generic types in expression context
2017-05-23 12:57:34 -07:00
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