Commit Graph

4105 Commits

Author SHA1 Message Date
Joe Groff
3c505753ad Test that @objc inference rejects methods that take non-@objc-able closure parameters.
A closure can only be bridged if its arguments and returns can. Make the diagnostic for non-bridgeable function types a bit more precise too.

Swift SVN r18166
2014-05-16 03:24:30 +00:00
Joe Groff
6b74826898 Improve diagnostic for @UIApplication mixed with top-level code.
Drop a note in the source file containing the top-level code to make it easier to navigate to (and avoid hardcoding the magic "main.swift" name).

Swift SVN r18093
2014-05-15 01:14:59 +00:00
Joe Groff
6e13190f47 Diagnose when @UIApplicationMain tries to coexist with a main.swift file.
Swift SVN r18072
2014-05-14 16:10:29 +00:00
Joe Groff
d3f7c1374e Allow @objc on local-scope classes.
Now that runtime class names are mangled we should be able to safely allow local classes to be @objc without unduly polluting the class namespace. <rdar://problem/16844347>

Swift SVN r18064
2014-05-14 05:31:28 +00:00
Joe Groff
09d8d68099 Allow at most one main class per module.
Register valid @UIApplicationMain classes with the enclosing module, and diagnose when we see more than one.

Swift SVN r18061
2014-05-14 04:40:30 +00:00
Joe Groff
067f810be6 Parse and do basic checking for @UIApplicationMain.
Introduce the UIApplicationMain attribute, and check that it's only applied to nongeneric classes that conform to UIApplicationDelegate.

Swift SVN r18048
2014-05-14 01:06:52 +00:00
Doug Gregor
f11e992f23 A local cannot be captured before it is declared <rdar://problem/16747992>.
Swift SVN r18025
2014-05-13 21:28:09 +00:00
Ted Kremenek
0b89fd4230 Fix bad grammar in diagnostic (<rdar://problem/16883149>).
Swift SVN r17996
2014-05-13 05:26:32 +00:00
Jim Ingham
14a6697ba5 Add an attribute marking the "Debugger function" lldb uses for emulating
local contexts.  Get the parser in consultation with the DebuggerClient
to handle moving persistent declarations from the debugger function to the
source file.

<rdar://problem/15302321> [ER] Define Swift classes in expressions


Swift SVN r17948
2014-05-12 19:03:31 +00:00
Chris Lattner
d751b58950 remove the prohibition of weak pointers being implicitly unwrapped, and update some testcases I
missed on previous commits.  This fixes:
<rdar://problem/16792095> QoI: misleading error message when trying to make a weak property be implicitly-unwrapped optional

and enables a useful pattern, where implicitly unwrapped weak pointers don't require !'ing on every use.



Swift SVN r17940
2014-05-12 16:46:33 +00:00
Doug Gregor
4b6910d497 Improve the diagnostic when we find an extraneous '()' <rdar://problem/16784814>.
Swift SVN r17927
2014-05-12 06:33:56 +00:00
Chris Lattner
3d69d427c5 lazy properties currently don't work correctly when observed, for the same
reasons as local properties not working.  


Swift SVN r17924
2014-05-12 03:41:19 +00:00
Chris Lattner
68fcf04b62 Lazy properties don't currently work in non-type-context (e.g. as local
variables) because I can't inject synthesized decls into the parent declcontext
correctly.  This sux and is fixable eventually, but until I do, reject these with
a clean error.


Swift SVN r17922
2014-05-12 03:27:51 +00:00
Chris Lattner
65841e81b7 reject @NSManaged properties marked @NSCopying, and reject @lazy properties
that have a missing or unsupported initializer.



Swift SVN r17906
2014-05-12 00:46:13 +00:00
Chris Lattner
ed76b03ede Several small things:
1) Change our "static variables not yet supported in classes" error to 
   print as "class variables not yet support".
2) Add a sema testcase for @NSManaged
3) Move NSManaged type checking logic to TypeCheckAttr.cpp to follow the
   form of the other attributes, and to benefit from the infrastructure there.




Swift SVN r17885
2014-05-11 20:59:29 +00:00
Chris Lattner
50075eb77b reject the @lazy attribute on globals, static fields, and protocol requirements.
Swift SVN r17880
2014-05-11 19:11:08 +00:00
Chris Lattner
d79646e962 parse and start type checking of @lazy attribute.
Swift SVN r17877
2014-05-11 18:37:29 +00:00
Doug Gregor
dc3ca1145d Loosen the constraints on bridging Dictionary<K, V>.
We now allow bridging so long as both K and V can be bridged to
Objective-C, as determined by _BridgedToObjectiveC conformance. Note
that Dictionary's implementation still needs to handle this, which is
tracked separately.

Swift SVN r17859
2014-05-11 00:08:41 +00:00
Chris Lattner
2b601c60d0 Implement: <rdar://problem/16877304> weak let's should be rejected
weak variables can change at runtime, which means that two loads from
the same let could produce two different results.  We have a concept for
this, it is called 'var'.

unowned pointers are not subject to this restriction of course.


Swift SVN r17847
2014-05-10 21:29:16 +00:00
Chris Lattner
24aa50069d Adjust diagnostics now that weak/unowned aren't attributes
Swift SVN r17800
2014-05-09 21:11:28 +00:00
Joe Pamer
a17cec6cb2 Some test and diagnostic cleanup:
- Mine conjunction constraints for constraint failure data. (rdar://problem/16833763)
- Rather than crash, add a diagnostic to signify a missing user constraint. (rdar://problem/16747055) I don't have a deterministic repro for this to include as a test, but users hit it from time to time, I'd like to address this issue holistically, and we're hoping that the new diagnostic will help us collect isolated repros.
- As promised, remove the temporary "compiler_submit_version" build configuration predicate in time for WWDC. (rdar://problem/16380797)

Swift SVN r17705
2014-05-08 18:46:08 +00:00
Jordan Rose
017f7e0ce2 Revert "Emit an error when the user tries to import a submodule."
Even though declarations end up in the top-level module, this can still
/expose/ them if the submodule is explicit. I'll have to think more about
this.

This reverts r17656 / <rdar://problem/16818519>

Swift SVN r17668
2014-05-08 01:45:13 +00:00
Jordan Rose
ac59e5772a Emit an error when the user tries to import a submodule.
<rdar://problem/16818519>

Swift SVN r17656
2014-05-08 00:12:59 +00:00
Jordan Rose
5e53c3afb6 Allow IBOutlet to appear on properties of array type.
...if the element type is an ObjC class or protocol type.

This currently only works if the element type is AnyObject;
that restriction will be lifted (on all @objc methods) once array bridging
is fully in place.

<rdar://problem/15607154>

Swift SVN r17574
2014-05-06 22:50:34 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +00:00
Doug Gregor
98a359bd38 Keyword argument QoI: diagnostic missing/extra arguments directly.
Swift SVN r17368
2014-05-04 06:21:49 +00:00
Joe Pamer
62f9932795 Accept an Identifier instead of a StringRef in the new "could not find member" diagnostic.
Swift SVN r17342
2014-05-04 00:22:11 +00:00
Doug Gregor
4f7a3d40cf Start enforcing strict keyword argument usage and ordering under -strict-keyword-arguments.
Implement a completely new path for matching up an argument tuple to a
parameter tuple, which handles the specific rules we want for
calls. The rules are:

  - The keyword arguments at the call site must match those of the
    declaration; one cannot omit a keyword argument if the declaration
    requires it, nor can one provide a keyword argument if the
    declaration doesn't have one.
  - Arguments must be passed in order, except that arguments for
    parameters with defaults can be re-ordered among themselves (we
    can't test all of this because neither constraint application nor
    the AST can express these).

QoI is extremely important in this area, and this change improves the
situation considerably. We now provide good diagnostics for several
important cases, with Fix-Its to clean up the code:

  - Missing keyword arguments:

    t.swift:8:13: error: missing argument labels 'x:y:' in call
    allkeywords1(1, 2)
                ^
                 x: y:

  - Extraneous keyword arguments:

    t.swift:17:12: error: extraneous argument labels 'x:y:' in call
    nokeywords1(x: 1, y: 1)
               ^~~~   ~~~

  - General confusion over keyword arguments (some missing, some
    wrong, etc.):

    t.swift:26:14: error: incorrect argument labels in call (have
        'x:_:z:', expected '_:y:z:')
    somekeywords1(x: 1, 2, z: 3)
                 ^~~~
                        y:

There are still a few areas where the keyword-argument-related
diagnostics are awful, which correspond to FIXMEs in this
implementation:

  - Duplicated arguments: f(x: 1, x: 2)
  - Extraneous arguments: f(x: 1, y: 2, z: 3) where f takes only 2
    parameters
  - Missing arguments
  - Arguments that are out-of-order
  - Proper matching of arguments to parameters for diagnostics that
    complain about type errors.

And, of course, since this has only been lightly tested, there are
undoubtedly other issues lurking.

This new checking is somewhat disjoint from what constraint
application can handle, so we can type-check some things that will
then fail catastrophically at constraint application time. That work
is still to come, as is the AST work to actually represent everything
we intend to allow.

This is part of <rdar://problem/14462349>.

Swift SVN r17341
2014-05-03 23:58:09 +00:00
Joe Pamer
96afbe7ae6 Remove "expression does not type-check".
Swift SVN r17337
2014-05-03 23:03:52 +00:00
Doug Gregor
774358cf03 Handle argument label mismatches due to single-element tuples.
We want to eliminate single-element tuples, but for now we need to
keep them from crashing the compiler. Fixes
<rdar://problem/16795899>.

Swift SVN r17286
2014-05-02 23:09:18 +00:00
Joe Pamer
8d6914b903 Tweak error message for overload resolution failures.
Swift SVN r17258
2014-05-02 17:32:21 +00:00
Joe Pamer
66391bd9e9 More improvements to constraint solver diagnostics.
Swift SVN r17256
2014-05-02 17:32:19 +00:00
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
411dc3bfd6 Mention NSManaged when complaining about stored properties without initial values.
Finishes <rdar://problem/16736676>.


Swift SVN r17210
2014-05-02 00:08:24 +00:00
Doug Gregor
79c7af43ce Implicitly turn @NSManaged properties into computed properties.
Also diagnose 'let' @NSManaged properties and @NSManaged properties with
initial values.

Swift SVN r17169
2014-05-01 19:59:13 +00:00
Dave Abrahams
8e2e7e9bfc [stdlib] Hide all BuiltinXXXConvertible's
During String API review we decided these weren't for user consumption.

Swift SVN r17167
2014-05-01 19:35:50 +00:00
Doug Gregor
f3977e3f03 Introduce @NSManaged attribute with basic semantic analysis.
We're still missing a number of checks here, as well as the
functionality to turn @NSManaged properties into computed properties.

Swift SVN r17166
2014-05-01 18:55:32 +00:00
Argyrios Kyrtzidis
9418fb9948 [DiagnosticEngine] Mark module import diagnostic errors as 'fatal' errors, and supress subsequent diagnostics
to avoid a cascade of errors that drown out the original failure.

Swift SVN r17141
2014-05-01 05:24:48 +00:00
Doug Gregor
c9fd60155e Diagnose an extraneous keyword when calling a single-parameter function with no keyword argument.
This is the simplest case to test the infrastructure for
adding/removing/fixing keyword arguments at the call site that don't
line up with the keyword arguments in a declaration. Baby steps toward
<rdar://problem/14462349>.



Swift SVN r17136
2014-05-01 03:47:52 +00:00
Joe Pamer
47628dbfb6 A couple more simple tweaks to improve type-check error reporting.
Swift SVN r17099
2014-04-30 17:54:56 +00:00
Jordan Rose
930d94ef76 Note that @IBOutlet et al only apply to /instance/ members.
This changes diagnostics for @IBOutlet, @IBAction, and @IBInspectable.

Swift SVN r17050
2014-04-29 22:30:39 +00:00
Jordan Rose
9c8b9f7e36 Validate @IBAction method signatures.
// IBAction, OS X:
@IBAction func foo(sender: AnyObjCClassCompatibleType?)

// IBAction, iOS:
@IBAction func foo()
@IBAction func foo(sender: AnyObjCClassCompatibleType?)
@IBAction func foo(sender: AnyObjCClassCompatibleType?, event: UIEvent?)

All argument types may be unchecked-optional or non-optional as well.
This commit doesn't check that the second argument to an iOS action method
is a UIEvent; the user may want to declare it as AnyObject or perhaps some
other protocol, so I just left it unenforced.

I'm also drawing on my knowledge of Cocoa to disallow String as an IBAction
parameter. Array and Dictionary also shouldn't appear here and thus don't
need special-casing even when bridged.

Finishes up <rdar://problem/16281474>

Swift SVN r17049
2014-04-29 22:30:36 +00:00
Dmitri Hrybenko
669f633070 Add "single extended grapheme cluster" literals (SEGCL) -- a subset of
double-quoted string literals that contain a single extended grapheme cluster

SEGCL by default infer type String, but you can ask to infer Character
for them.

Single quoted literals continue to infer Character.

Actual extended grapheme cluster segmentation is not implemented yet,
<rdar://problem/16755123> Implement extended grapheme cluster
segmentation in libSwiftBasic

This is part of
<rdar://problem/16363872> Remove single quoted characters

Swift SVN r17034
2014-04-29 14:08:16 +00:00
Joe Pamer
519e0ec82d Tweak the heuristics for mining inactive constraints for possible reasons why a constraint system failed to converge on a solution. (For the time-being, favor conversion and overload constraints over others.)
Swift SVN r16994
2014-04-28 21:05:40 +00:00
Joe Pamer
1beb2db860 Begin QOI work for rdar://problem/16007230 by making it possible to get slightly more precise constraint solver errors when using the detailed-diagnostics flag.
The work has obviously barely begun, but this change may be immediately useful to some people.

Swift SVN r16989
2014-04-28 19:13:08 +00:00
Doug Gregor
d93c78ceda Ban @weak unchecked optionals <rdar://problem/16738545>.
Swift SVN r16961
2014-04-28 06:16:21 +00:00
Doug Gregor
a9fafbd44f Replace "by reference" with "to an inout parameter" for less misleadingness
Swift SVN r16952
2014-04-27 22:50:03 +00:00
Doug Gregor
3dfaddb674 Drop extraneous '()' applied to a non-function.
Fixes <rdar://problem/15042686>, i.e.,

t.swift:3:7: error: call to non-function of type 'Int'; did you mean
    to leave off the '()'?
  i = i()
      ^~~

Swift SVN r16950
2014-04-27 22:36:39 +00:00
Joe Groff
1b60411701 english -pedantic
Swift SVN r16947
2014-04-27 22:07:34 +00:00