Commit Graph

158 Commits

Author SHA1 Message Date
Doug Gregor
937504bc5e Restrict the array-bridged conversion to non-verbatim bridging.
This allows, e.g., String[] -> NSString[] and String[] -> NSObject[]. Part of <rdar://problem/16952238>.

Swift SVN r18290
2014-05-18 00:42:00 +00:00
Doug Gregor
8215dff6c3 A trailing closure means that a keyword argument can be omitted, not wrong.
Fixes the type checker issue reported in <rdar://problem/16909180>.

Swift SVN r18260
2014-05-17 17:59:17 +00:00
Joe Pamer
b10a2bf48a Fix regression in implicit conversions of implicitly unwrapped optional AnyObject types to their contextual types. (rdar://problem/16922332)
Swift SVN r18203
2014-05-16 18:13:35 +00:00
Joe Pamer
50ef69c745 Allow for implicit forcing of enumerated unchecked optional values. (rdar://problem/16265970, rdar://problem/16569776, rdar://problem/16931457)
Swift SVN r18145
2014-05-16 00:06:39 +00:00
Joe Pamer
a74c44a6e4 Fix two crashing bugs related to checked downcasts - rdar://problem/16093456 and rdar://problem/16892211.
Swift SVN r18118
2014-05-15 18:36:44 +00:00
John McCall
fc57ea2cf8 Add __conversion as a known identifier.
Swift SVN r18068
2014-05-14 08:19:20 +00:00
Doug Gregor
80a85d3670 Improve handling of repeated keyword arguments missing at the call site.
Fixes <rdar://problem/16900465>.

Swift SVN r18043
2014-05-14 00:20:04 +00:00
Joe Pamer
5d95457efc Disallow operator overloads that require implicit conversions for all arguments (rdar://problem/16785445)
Swift SVN r18019
2014-05-13 20:09:50 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Doug Gregor
9c03b4f924 Miscellaneous cleanups for array bridging in the type checker.
Use protocol conformance checks whenever we want to determine whether
a value type is bridged to an Objective-C class, which is simpler and
more robust. Clean up some of the type checker code around bridging,
using TypeBase::isEqual() to compare types and looking through type
sugar more regularly.

As part of this, move Array's conformance to
_ConditionallyBridgedToObjectiveC into the Foundation overlay. This
lets us use NSArray as the bridged type (which is clearer than using
CocoaArray), and follows what we're doing for dictionary bridging.


As part of this, move Array's bridged-to-


Swift SVN r17868
2014-05-11 05:13:24 +00:00
Joe Groff
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Doug Gregor
05a283a58c When dealing with argument tuple conversions, keep the parentheses around
This is fairly ugly, because we're halfway between a-function-type-takes-a-tuple and a-function-type-takes-a-set-of-parameters. However, it's another step toward -strict-keyword-arguments.

Swift SVN r17727
2014-05-08 23:20:47 +00:00
Joe Groff
1dce36edd2 Make 'T.self is U.Type' work.
Fix up all of type-checking, SILGen, IRGen, and the runtime to support checked casts of metatypes. <rdar://problem/16847453>

Swift SVN r17719
2014-05-08 22:55:14 +00:00
Joe Pamer
f3e6b31887 Fix a problem with the type checker trying to create user conversion expressions out of like-types. (rdar://problem/16837295)
Swift SVN r17669
2014-05-08 02:07:53 +00:00
Joe Pamer
709da29301 Implement checks for conditionally bridged types when performing a bridged conversion between array types. (rdar://problem/16540403)
Swift SVN r17660
2014-05-08 00:58:30 +00:00
Doug Gregor
36cbcccbe9 Generalize constraint application under -strict-keyword-arguments.
Introduce a new locator kind for argument/parameter comparisons that
tracks both the argument and the parameter, which we will eventually
use in diagnostics more regularly. For now, this helps us smooth over
scalar-to-tuple/tuple-to-tuple/tuple-to-scalar nonsense when dealing
with calls.

Fix a pile of fallout from this change.

Swift SVN r17648
2014-05-07 22:36:49 +00:00
Doug Gregor
3bd0d6976f Reimplement constraint application for strict keyword arguments.
Swift SVN r17647
2014-05-07 22:36:47 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +00:00
Doug Gregor
8802bbc8eb Factor out the argument/parameter matching of matchCallArguments(). NFC
We're going to want to re-use the argument/parameter matching of
matchCallArguments() elsewhere, so separate it from the constraint system.

Swift SVN r17626
2014-05-07 13:09:50 +00:00
Doug Gregor
41a6c97d97 Generalize call argument/parameter patching to work on tuple type element arrays.
This is a small step toward subsuming scalar-to-tuple and
tuple-to-scalar conversions.

Swift SVN r17623
2014-05-07 12:23:57 +00:00
Joe Pamer
edb4946f66 Begin updating type checking of array upcasts to conform with the new spec.
Also, call through DaveA's new entry point for upcasts on Array<T>.

Swift SVN r17564
2014-05-06 21:32:22 +00:00
Joe Pamer
d22ffa8cb8 Re-lazify the addition of equatable conformances to imported enum types. (rdar://problem/16808612)
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.

Swift SVN r17557
2014-05-06 19:56:29 +00:00
Jordan Rose
3e917be738 Use full DeclNames for dynamic lookup of calls.
Previously, we were just using the base name, which resulted in massive
inefficiency when dealing with Clang (we basically had to check every
selector in the system to see if it had the same first selector piece).
I've hacked ConstraintSystem a bit to carry a map from UnresolvedDotExpr
to the ApplyExpr that consumes it, so that we can use the full DeclName
and look up methods by full selector.

Now that dynamic lookup is fast, re-enable it for the
Foundation_bridge.swift test. (r17520 actually provided most of the benefit.)

This does break selector lookup on AnyObject when doing selector splitting,
and slightly regresses diagnostics when you try to call a method on AnyObject
and forget a parameter name.

<rdar://problem/16808651>. Part of the Playground performance efforts.

Swift SVN r17524
2014-05-06 02:35:08 +00:00
Doug Gregor
26a3594481 Keyword arguments: handle scalar-to-tuple conversions better.
Swift SVN r17503
2014-05-05 23:58:19 +00:00
Joe Pamer
11441abc4b Rather than special-case NSString conversions in the type checker, utilize the _BridgedToObjectiveC protocol conformance on the type being converted if available. This will allow us to more broadly accommodate bridged conversions between types.
Swift SVN r17482
2014-05-05 19:40:03 +00:00
Doug Gregor
254e5741fd Strict keyword arguments: allow trailing closures in scalar-to-tuple conversions.
Swift SVN r17449
2014-05-05 15:42:16 +00:00
Doug Gregor
ecb7612797 Strict keyword arguments: handle trailing closures harder.
Cope with lvalue types, optionals.


Swift SVN r17416
2014-05-05 03:40:23 +00:00
Doug Gregor
545eb3be31 Strict keyword arguments: fix locator for conversions.
We were getting constraint application failures under
-strict-keyword-arguments due to the wrong locator getting passed
down.


Swift SVN r17415
2014-05-05 03:33:53 +00:00
Doug Gregor
a039bd5a42 Keyword arguments: don't require keywords for trailing closures.
This implementation accepts more than it should, because we don't
reliably have enough information in the constraint solver to know
whether an argument is actually a trailing closure or not.

Swift SVN r17404
2014-05-04 21:38:44 +00:00
Doug Gregor
340e94700d Keyword argument QoI: use typo correction to help match keyword arguments to parameters.
This replaces this poor positional correction:

t.swift:3:10: error: incorrect argument labels in call (have 'baz:wobble:', expected 'withFoo:bar:')
mismatch1(baz: 1, wobble: 2)
         ^~~~     ~~~~~~
          withFoo bar

with a much better one:

t.swift:3:10: error: incorrect argument labels in call (have 'baz:wobble:', expected 'bar:wibble:')
mismatch1(baz: 1, wobble: 2)
         ^~~~     ~~~~~~
          bar     wibble

Swift SVN r17385
2014-05-04 15:13:47 +00:00
Doug Gregor
98a359bd38 Keyword argument QoI: diagnostic missing/extra arguments directly.
Swift SVN r17368
2014-05-04 06:21:49 +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
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
667d90c1f4 Start diagnosing scalar-to-tuple conversions that are missing a keyword argument.
Another baby step toward <rdar://problem/14462349>, made even more
tepid by the fact that I've quarantined this behind a new flag,
-strict-keyword-arguments. Enforcing this breaks a lot of code, so I'd
like to bring up the new model on the side (with good diagnostics that
include Fix-Its) before trolling through the entire standard library
and testsuite to fix violations of these new rules.


Swift SVN r17143
2014-05-01 06:15:30 +00:00
Doug Gregor
2b1cb6c101 My general "relabel tuple" fix kind isn't going to fly; use TupleToScalar for the existing case.
Swift SVN r17139
2014-05-01 04:45:59 +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
Doug Gregor
97a2df25c5 Add a new conversion and type-matching kind for argument tuples.
We're going to give argument-tuple handling special behavior; separate
it out first.

Swift SVN r17095
2014-04-30 15:32:50 +00:00
Doug Gregor
d8a71c4866 Type checker: encapsulate fix kind into a Fix class, which will grow. NFC
Swift SVN r17094
2014-04-30 14:24:08 +00:00
Chris Lattner
29aca1c851 Various minor TypeExpr improvements:
- Change astdumper to print the typerepr in the more canonical syntax.
 - Remove bogus logic from CSApply that was preventing us from rewriting
   TypeExprs properly
 - Teach CSGen to handle unbound generics correctly (thanks to Doug for the help on this)



Swift SVN r17007
2014-04-29 02:58:43 +00:00
Chris Lattner
a7012f23ef Remove swift::ArrayType. It is dead and vestigial code for supporting fixed size
arrays, which never got baked.  Remove it until we have time to do things right.


Swift SVN r16995
2014-04-28 21:18:27 +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
Ted Kremenek
6caf910d32 Implement new syntactic sugar for UncheckedOptional<T>.
This leaves in the existing syntax for @unchecked T?.  That will
be addressed in later patches.

There's still a mysterious case where some of the SIL output
includes UncheckedOptional<T> and some places T!.

Moreover, this doesn't handle SourceKit's behavior for printing
for overrides.  This just handles parsing the 'T!' syntax.

Swift SVN r16945
2014-04-27 21:59:29 +00:00
Doug Gregor
beb43749f1 Suggest '&' when it is needed to pass an lvalue by reference.
Fixes <rdar://problem/11592572>.

Swift SVN r16944
2014-04-27 21:42:06 +00:00
Doug Gregor
35eecfe835 Speculatively suggest '!' when treating an AnyObject as a class.
Swift SVN r16943
2014-04-27 21:42:05 +00:00
Doug Gregor
1edd7a3986 Speculatively suggest '!' when treating an AnyObject as a class.
Swift SVN r16939
2014-04-27 20:41:03 +00:00
Doug Gregor
eaf2bf632f Speculatively fix optionals by unwrapping them with '!'.
Example:

test/Constraints/fixes.swift:54:9: error: value of optional type 'B?'
    not unwrapped; did you mean to use '!' or '?'?
  b = a as B
        ^
            !

Swift SVN r16938
2014-04-27 20:41:02 +00:00
Doug Gregor
321911a059 Add infrastructure for applying fixes during constraint solving.
Introduce some infrastructure that allows us to speculatively apply
localized fixes to expressions during constraint solving to fix minor
typos and omissions. At present, we're able to introduce the fixes
during constraint simplification, prefer systems with fewer fixes when
there are multiple fixes, and diagnose the fixes with Fix-Its.

Actually rewriting the AST to reflect what the Fix-Its are doing is
still not handled.

As a start, introduce a fix that adds '()' if it appears to have been
forgotton, producing a diagnostic like this if it works out:

t.swift:8:3: error: function produces expected type 'B'; did you mean
to call it with '()'?
f(g)
  ^
   ()

Note that we did regress in one test case
(test/NameBinding/multi-file.swift), because that diagnostic was
getting lucky with the previous formulation.

Swift SVN r16937
2014-04-27 19:04:04 +00:00
Chris Lattner
371a9316f4 - Introduce a new 'nonmutating' context sensitive keyword, and use it instead of @!mutating.
- Change the parser to unconditionally reject @mutating and @!mutating with a fixit and 
  specific diagnostic to rewrite them into the [non]mutating keyword.
- Update tests.

This resolves <rdar://problem/16735619> introduce nonmutating CS keyword and remove the attribute form of mutating all together



Swift SVN r16892
2014-04-26 21:00:06 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00