Commit Graph

16 Commits

Author SHA1 Message Date
Chris Lattner
aad3cf9e10 Factor out structural error diagnostics out to a helper method (allowing
the code to be actually readable since it unnests it greatly), and call it
both before and after argument type validation.  This allows us to capture
many more structural errors than before, leading to much better diagnostics
in a lot of cases.  This also fixes the specific regressions introduced by
96a1e96.
2015-12-07 23:48:29 -08:00
Joe Groff
bebfa969bd Sema: Allow 'x.init' references on metatype expressions.
If 'x.init' appears as a member reference other than 'self.init' or 'super.init' within an initializer, treat it as a regular static member lookup for 'init' members. This allows a more explicit syntax for dynamic initializations; 'self.someMetatype()' looks too much like it's invoking a method. It also allows for partial applications of initializers using 'someMetatype.init' (though this needs some SILGen fixes, coming up next). While we're in the neighborhood, do some other correctness and QoI fixes:

- Only lookup initializers as members of metatypes, not instances, and add a fixit (instead of crashing) to insert '.dynamicType' if the initializer is found on an instance.
- Make it so that constructing a class-constrained archetype type correctly requires a 'required' or protocol initializer.
- Warn on unused initializer results. This seems to me like just the right thing to do, but is also a small guard against the fact that 'self.init' is now valid in a static method, but produces a newly-constructed value instead of delegating initialization (and evaluating to void).

Swift SVN r29344
2015-06-08 04:11:28 +00:00
Chris Lattner
7059871abf Convert some 'var' bindings to 'let' when they are not mutated, some
var/let bindings to _ when they are never used, and use some values that
are only written.  This is a testsuite cleanup, NFC. More to come.


Swift SVN r28406
2015-05-11 00:20:55 +00:00
Chris Lattner
23b713abed fix typo in diagnostic.
Swift SVN r27873
2015-04-28 17:04:00 +00:00
Chris Lattner
88e50659f7 fix <rdar://problem/17564699> QoI: Structs should get convenience initializers
The diagnostic we were producing was confusing the user into thinking that
you couldn't have a delegating init on a struct.  Improve the diagnostic and
add a fixit hint.



Swift SVN r27872
2015-04-28 17:01:48 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Doug Gregor
ece743ea3b Record overrides of convenience initializers.
Even though we don't require the 'override' keyword for convenience
initializers, we still have override semantics for them. This
manifests in, for example, name lookup and ambiguity resolution.


Swift SVN r21696
2014-09-04 05:33:46 +00:00
Doug Gregor
4645d0050b Don't inherit a designated initializer if there is already a convenience initializer with the same signature <rdar://problem/17785840>.
Swift SVN r21075
2014-08-06 21:26:03 +00:00
Doug Gregor
26816e2b8c QoI: Improve diagnostic for a missing required initializer with a Fix-It.
When a subclass is missing a required initializer, produce an error
within the subclass that mentions the required initializer along with
a Fix-It that provides an initializer stub, e.g.,

  required init(coder aDecoder: NSCoder!) {
      fatalError("init(coder:) has not been implemented")
  }

We take care to insert this stub in the main class, after all of the
initializers (if there are any) or near the beginning of the class (if
there aren't any initializers), and try to match the existing
indentation. If this works out, we should handle unsatisfied protocol
requirements the same way. <rdar://problem/17923210>

Swift SVN r21055
2014-08-06 00:33:54 +00:00
Doug Gregor
11d49335d3 Customize diagnostic for calls to super.init within a convenience initializer <rdar://problem/17922223>.
Swift SVN r21046
2014-08-05 22:16:20 +00:00
Doug Gregor
a27179c0bc Don't diagnose the lack of self.init during type checking <rdar://problem/17922223>.
self.init isn't needed if the initializer never returns (e.g., if it
calls fatalError), so let DI diagnostic this. DI doesn't produce as
nice a diagnostic, however.

Swift SVN r21044
2014-08-05 22:00:58 +00:00
Doug Gregor
5fc8ac7fd1 Require the 'override' keyword for initializers that override designated initializers.
Swift SVN r20490
2014-07-24 15:38:33 +00:00
Doug Gregor
4521194e91 Improve diagnostic for missing 'required' initializers.
We have useful DeclNames now; use them.

Swift SVN r20431
2014-07-23 22:16:39 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
571ae697d5 Parsing and AST support for complete object initializers.
Enforce that complete object initializers always be delegating.

Swift SVN r14549
2014-03-01 00:51:18 +00:00