Commit Graph

4105 Commits

Author SHA1 Message Date
Chris Lattner
3830face44 Carve out a new TypeCheckAttr.cpp file, and sketch out a new structure for doing
attribute checking on a per attribute basis.  It makes a lot more sense for a 
given attribute to think about all of the decl kinds it may or may not apply to
rather than all decl kinds thinking about the cross products of attributes they 
may apply to.

Start by adding a new check to reject @final in structs and enums.


Swift SVN r15925
2014-04-04 05:08:23 +00:00
Doug Gregor
9ca6a394d4 Diagnose attempts to override a 'final' declaration.
Swift SVN r15905
2014-04-03 23:53:18 +00:00
Doug Gregor
6b71d48a97 When overriding a declaration, complain if the @objc names don't match.
Swift SVN r15901
2014-04-03 22:57:15 +00:00
Doug Gregor
53914c42a2 Remove the prohibition on "tuple-style" @objc methods.
Swift SVN r15847
2014-04-02 23:35:02 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Ted Kremenek
4a6edd4abf For 'undeclared type' errors for remapped types, put the fixit with the error itself.
This finishes up <rdar://problem/16427080>.

Swift SVN r15688
2014-03-31 17:48:25 +00:00
Ted Kremenek
fb22ec4c6e Fix grammar in diagnostic I just added.
Swift SVN r15669
2014-03-31 07:44:46 +00:00
Ted Kremenek
39dc97738b For "unknown declared type" errors involving remapped types, suggest the remapped type as a fixit.
For example:

  func foo(a: id)

now gets a fixit to turn 'id' into 'AnyObject'.

This relies on the ClangImporter recording the translation as it
processes declarations whose types are remapped.

Swift SVN r15668
2014-03-31 07:10:32 +00:00
Ted Kremenek
8ddd56e28f Don't allow 'unavailable' methods to be overridden.
Swift SVN r15646
2014-03-30 08:22:34 +00:00
Doug Gregor
e07f347803 Allow one to specify @objc(name) on getters and setters of abstract storage declarations.
.. but not other accessors, such as willSet/didSet. These annotations
aren't useful for anything yet.


Swift SVN r15639
2014-03-30 00:09:05 +00:00
Doug Gregor
9ceefe8de4 @objc methods and initializers must have the right number of ':'s.
Swift SVN r15630
2014-03-29 20:38:13 +00:00
Doug Gregor
927362eeb7 @objc subscripts cannot have a name
Swift SVN r15628
2014-03-29 20:06:01 +00:00
Doug Gregor
936d26e213 @objc naming: classes, protocols, and properties must have simple names.
Swift SVN r15627
2014-03-29 20:00:04 +00:00
Joe Groff
953c93d936 Sema: Rework inout conversion to do simple member lookup instead of using a protocol.
We'll need types to be convertible from multiple kinds of inouts, which currently can't be represented with protocol conformance since we only allow one protocol conformance per type per protocol. Instead just look for a magic "__inout_conversion" static method in the type; this is lame but easy, and inout conversions shouldn't be available outside of the stdlib anyway.

Swift SVN r15599
2014-03-29 02:50:32 +00:00
Joe Groff
46f77c6181 Sema: Build the AST for inout address conversions.
Add two new AST node types:

- InOutConversionExpr, which represents an '&x' expression that involves inout conversion. This will be a signal to SILGen not to introduce a writeback scope for the nested conversion call.

- LValueToPointerExpr, which represents the primitive '@lvalue T' to 'RawPointer' conversion that produces the argument to the inout conversion.

Build an InOutConversionExpr AST when an inout expression is resolved by a conversion to an BuiltinInOutAddressConvertible type.

Swift SVN r15594
2014-03-29 02:50:25 +00:00
Ted Kremenek
7591420e8b Start wiring up @availability checking for types.
As a use case, declare a new 'NSUInteger' (which the importer maps to 'Int'
when importing from Objective-C) and mark it unavailable with a
helpful message.  This will eventually go to the Foundation overlay
once @availability is properly serialized.

There's some duplication in availability checking.  That will get
consolidated as more of it gets written.  It's not very comprehensive
right now.

Swift SVN r15583
2014-03-28 18:40:09 +00:00
Ted Kremenek
b9ac56302c Wire up initial diagnostics for checking 'unavailable' declarations.
There's a lot of detail work to do here, and obviously more
test cases.

Swift SVN r15510
2014-03-26 15:05:13 +00:00
Chris Lattner
ac00f1f07a improve the wording of a diagnostic, thanks to Jordan for pointing this out.
Swift SVN r15323
2014-03-21 03:49:01 +00:00
Chris Lattner
2deecc85c0 Implement <rdar://problem/16375910> reject observing properties @overriding readonly properties
Readonly properties have nothing to observe after all, so we should produce a new
diagnostic instead of a SILGen failure.



Swift SVN r15292
2014-03-20 20:41:39 +00:00
John McCall
607b326ab5 When type-checking downcasts, just optimistically
assume that we know about all the optional types in play.

This isn't correct for types that can dynamically be
more optional than they appear statically, e.g. archetypes
and existentials, but it's the easiest thing to do,
and there are workarounds.  I filed rdar://16374053
to handle doing the right thing.

Swift SVN r15254
2014-03-20 00:25:00 +00:00
Jordan Rose
d0fd672ad1 s/[objc]/@objc/ in one last stray diagnostic.
(Yes, I know I really need to escape those brackets.)

Swift SVN r15247
2014-03-19 21:11:49 +00:00
Dmitri Hrybenko
d1cffd3c18 @objc inference QoI: now that we don't allow plain classes, add a specialized
diagnostic for that case


Swift SVN r15235
2014-03-19 11:21:10 +00:00
Joe Groff
d67ad6e625 Reword diagnostics when non-literal values and types are used as enum raw values.
The interesting thing is that we require a literal, we don't need to enumerate all the possibilities. <rdar://problem/15711450>.

Swift SVN r15100
2014-03-15 02:02:10 +00:00
Doug Gregor
f474fafa42 Don't allow a designated initializer to be written in an extension.
Collecting all of the designated initializers into the class
definition itself gives us the complete story in one location, which
improves consistency.

Swift SVN r15088
2014-03-14 22:52:06 +00:00
Doug Gregor
00b0222709 Warn about our inability to inherit variadic designated initializers.
We'll emit a stub declaration, but we shouldn't be mysterious about
it. Part of <rdar://problem/16318855> that we'll actually implement at
some later point via <rdar://problem/16331406>.

We at least shouldn't be mysterious about it

Swift SVN r15082
2014-03-14 22:15:58 +00:00
Jordan Rose
455e96e955 @objc should be enough to make a protocol a class protocol.
There are very few times where we'd want to use @class_protocol outside of
@objc, and it feels weird to tell someone coming from Objective-C that they
need to mark their already-@objc protocol as @class_protocol. Instead, just
change ProtocolDecl::requiresClass to check for @objc.

(The commit checks for /both/ @objc-the-attribute and the IsObjC flag.
This is to give the right answer before type-checking, or at least the
likely-intended answer.)

<rdar://problem/16302887>

Swift SVN r15060
2014-03-14 17:56:07 +00:00
Doug Gregor
f94a5e5df4 Call a standard library entry point from initializer stubs.
Rather than simply trapping with no output, have the initializer stubs
call into a new standard library function _unimplemented_initializer
that emits a more reasonable diagnostic, containing the name of the
class, the name of the initializer, and the file/line/column where the
class itself is defined. This finishes <rdar://problem/16156996>.



Swift SVN r15049
2014-03-14 15:04:49 +00:00
Doug Gregor
539a0b450e Diagnose non-constructible classes.
When a particular class has no designated initializers explicitly
written or implicitly defined, complain and suggest initializers for
all of the stored properties that need them and appear to have
sensible default values. Fixes <rdar://problem/15670604>.



Swift SVN r15023
2014-03-14 01:39:11 +00:00
Joe Pamer
69be7f70cc These changes disallow non-generic classes from having a generic super class. (rdar://problem/16028169) It was decided to enact this restriction in the near-term because we're not currently able to IRGen such child classes correctly, but we'll definitely want to lift this restriction once we can do so.
Swift SVN r14980
2014-03-12 23:45:22 +00:00
Joe Groff
b8d48dd7bb Change 'x.type' to 'x.dynamicType'.
It's not a common operation, so it doesn't need a terse name that occupies valuable identifier real estate.

Swift SVN r14932
2014-03-11 23:18:33 +00:00
Dmitri Hrybenko
1bf6a1ec9f Diagnose @objc-incompatible requirements in @objc protocols
rdar://15798313


Swift SVN r14917
2014-03-11 14:29:51 +00:00
Joe Groff
020e9112b2 Sema: Don't allow NominalTypePatterns to match out static properties.
We don't allow static property access through instances in general, so also prevent it in case patterns.

Swift SVN r14850
2014-03-09 16:50:59 +00:00
Joe Groff
9f12e2e4a4 Enable same-type concrete constraints, e.g. <T: P where T.Assoc == Int>
Let ArchetypeType nested types and PotentialArchetypes be bound to concrete types in addition to archetypes. Constraints to outer context archetypes still suffer type-checker issues, but constraints to true concrete types should work now.

Swift SVN r14832
2014-03-08 17:18:17 +00:00
Chris Lattner
536b6e30ae Reapply r14811 and r14813 with fixes to not warn on anonymous closure arguments
and to not warn about switch case matching.  Other fixes to the stdlib were
already committed.


Swift SVN r14831
2014-03-08 07:35:45 +00:00
Doug Gregor
f91ab5f330 Revert r14811 and r14813; they break building the Foundation overlay.
Swift SVN r14829
2014-03-08 06:30:36 +00:00
Chris Lattner
7c48081197 Diagnose cases where we infer a variable to () or AnyObject type. This is
likely to be a bug (e.g. calling a function when you're looking to get a closure
in the first case, missing a type case in the second case).  We emit a note saying
that the warning can be silenced by adding an explicit type, e.g.:

t.swift:4:5: warning: variable 'x' inferred to have type '()', which may be unexpected
var x = print("")
    ^
t.swift:4:5: note: add an explicit type annotation to silence this warning
var x = print("")
    ^
      : ()
t.swift:7:5: warning: variable 'b' inferred to have type 'AnyObject', which may be unexpected
var b = a
    ^
t.swift:7:5: note: add an explicit type annotation to silence this warning
var b = a
    ^
      : AnyObject

This implements:
  <rdar://problem/15263687> Diagnose variables inferenced to 'AnyObject'
  <rdar://problem/16252090> Warning when inferring empty tuple type for declarations



Swift SVN r14811
2014-03-08 00:46:45 +00:00
Joe Groff
bd8b2d33e7 Fix typos in diagnostics.
Swift SVN r14802
2014-03-07 23:24:37 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
Chris Lattner
3348c46bf7 implement: <rdar://problem/16193162> Require specifying self for locations in code where strong reference cycles are likely
This requires that property references have an explicit "self." qualifier when in an
explicit closure expression, since self will be captured, not the property.

We don't do the same for autoclosures.  The logic here is that autoclosures can't 
practically be used in capturing situations anyway, since that would be extremely 
surprising to clients.  Further, forcing a syntactic requirement in an autoclosure
context would defeat the whole point of autoclosures: make them implicit.


Swift SVN r14676
2014-03-05 06:50:56 +00:00
Joe Pamer
484459b474 For 1.0, we're restricting the use of directly recursive protocol requirements. (They currently cause an infinite loop in the type checker.) We can look into opening this up post-1.0.
Swift SVN r14651
2014-03-04 21:02:26 +00:00
Doug Gregor
15be2159a2 Rename "abstract initializers" to "required initializers".
It's better than what we have.

Swift SVN r14620
2014-03-03 23:12:40 +00:00
Doug Gregor
8ceb345065 Speculatively rename complete object and subobject initializers.
Use "convenience initializer" and "designated initializer", respectively.

Swift SVN r14616
2014-03-03 22:37:47 +00:00
Doug Gregor
2c26523201 Require chaining to the superclass initializer to refer to a subobject initializer.
Swift SVN r14601
2014-03-03 18:47:09 +00:00
Doug Gregor
54a16c19ff Don't allow a subobject initializer to delegate to another initializer.
While it would be technically sound to do this, it almost surely means
that the user forgot the '-> Self' to make this a complete object
initializer. Provide a Fix-It to add the '-> Self'.

If we ever feel like we need this behavior, we can introduce a special
syntax for it.


Swift SVN r14598
2014-03-03 16:54:59 +00:00
Chris Lattner
7e3338c427 IRGen can't handle curried Objective-C methods. Instead of crashing on them, emit a nice
error message saying you can't do this.  This resolves:
<rdar://problem/15643576> Shouldn't crash on partial application of objc method



Swift SVN r14588
2014-03-03 07:59:25 +00:00
Doug Gregor
e4444e36cb Complete object initializers cannot be defined in a non-class.
Swift SVN r14550
2014-03-01 00:51:20 +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
Joe Groff
8e6b353542 Derive conformances of Equatable and Hashable for simple enums.
If an enum has no cases with payloads, make it implicitly Equatable and Hashable, and derive default implementations of '==' and 'hashValue'. Insert the derived '==' into module context wrapped in a new DerivedFileUnit kind, and arrange for it to be codegenned with the deriving EnumDecl by adding a 'DerivedOperatorDecls' array to NominalTypeDecls that gets visited at SILGen time.

Swift SVN r14471
2014-02-27 20:28:38 +00:00
Chris Lattner
2974c928b9 Reject 'inout' when not in parameter lists. This fixes some silgen crashes on
invalid code (the types.swift example), and a improves diagnostics in others (the
other testcase).

This is necessary but not sufficient to fix rdar://16146971.


Swift SVN r14465
2014-02-27 18:44:41 +00:00
Dmitri Hrybenko
cf82449090 Rename @IBLiveView to IBDesignable per request in rdar://16135911
Swift SVN r14462
2014-02-27 15:26:54 +00:00