Commit Graph

19 Commits

Author SHA1 Message Date
Slava Pestov
8a31bc7609 Add regression test for https://bugs.swift.org/browse/SR-6509 2017-12-08 12:54:03 -08:00
Pavel Yaskevich
05d524d6e0 [CSApply] Fix source breakage related to deep-equality types and SE-0110
Fix problem related to Swift 3 mode (with assertions),
since Swift 3 mode allows passing arguments with extra parens
to parameters which don't expect them, it should be supported
by "deep equality" types e.g. Optional<T>:

```swift
func foo(_: (() -> Void)?) {}
func bar() -> ((()) -> Void)? { return nil }
foo(bar) // This expression should compile in Swift 3 mode
```

Resolves: rdar://problem/35198459
2017-11-16 21:56:24 -08:00
Pavel Yaskevich
1ffac2e651 [QoI] Improve diagnostics related to member calls
When trying to diagnose problems related to calls where
function is represented by a member of nominal type let's
attempt to be more cautious while type-checking function
expression without it's arguments, because it could produce
unrelated diagnostics.

Resolves: rdar://problem/32551313, rdar://problem/28456467, rdar://problem/31671195
2017-06-27 15:49:11 -07:00
Pavel Yaskevich
3a77295835 [QoI] Use information known about call parameters via failed constraint
This makes it a lot easier to diagnose contextual mismatch related
to arguments used by the call without relying on the type of the
function expression which is not always available.
2017-06-21 11:27:12 -07:00
Pavel Yaskevich
817798151a [QoI] Add a fix-it with missing parameters for closures
If there are parameters missing in the closure declaration and
all of the present ones are anonymous let's emit a fix it suggesting
missing parameters.

Resolves: rdar://problem/32301091
2017-05-22 15:10:41 -07:00
Pavel Yaskevich
ead1447aa1 [QoI] Extend single tuple parameter diagnostics to function/subscript calls
Properly diagnose cases of function/subscript argument tuple
structuring/destructuring related by not limited to SE-0110.

Resolves: rdar://problem/31973368
2017-05-15 18:41:41 -07:00
Pavel Yaskevich
c72b402afa [QoI] Improve diagnostics for generic subscripts
While diagnosing index expression associated with subscript call
`validateContextualType` didn't look through TupleType to identify
potential nullability of the contextual type related to generic
parameters.

Resolves: rdar://problem/31724211
2017-05-08 02:41:02 -07:00
Joe Groff
cf6cc484c0 Switch on key paths.
Enabling the global subscript degrades some diagnostics (rdar://problem/31724211).
2017-05-05 08:32:41 -07:00
Slava Pestov
88e48c901e Add test for SR-4378
This snippet type checks in Swift 4 mode, but not in Swift 3.

It used to work in Swift 3.0, so something broke when we
implemented SE-0110 and redid the Swift 3 mode emulation.
2017-04-20 00:07:06 -07:00
Joe Groff
7eaa507ced Sema: Ban single-labeled element tuples harder.
The prohibition in Swift 3.0 missed the case where the single-element tuple was wrapped in extra parens as the only argument of a function. We've ripped out parts of the type checker that try to cope with single-element tuples, and it would be risky and bug-prone to try to admit this code, so it's better to fix the ban than to try to accept the code, alas. Fixes SR-3788.
2017-02-06 13:54:32 -08:00
Slava Pestov
71cf245701 Merge pull request #7023 from KingOfBrian/bugfix/SR-2115
Generate unused variable warnings in top level statements
2017-01-29 20:25:46 -08:00
Jordan Rose
7c8117301a In Swift 3 mode, allow "tuple unsplatting" in certain cases. (#7077)
Swift 3.0 allowed constructing an enum or calling a function-typed
property with multiple arguments even when a single argument of tuple
type was expected. Emulate that in Swift 3 mode by wrapping in an
extra level of parentheses when the situation comes up.

Last vestiges of fallout from SE-0110. Hopefully last, anyway. A nice
follow-up to this commit might be to /warn/ in Swift 3 mode when this
happens.

rdar://problem/30171399
2017-01-27 11:19:07 -08:00
Brian King
0c57aebfea Fix unit tests 2017-01-26 10:04:41 -05:00
Slava Pestov
46b543478f AST: Don't canonicalize type when profiling specialized conformances
Completes the fix of <rdar://problem/29739905>.
2017-01-19 20:07:05 -08:00
Slava Pestov
a22b46244c Sema: Don't canonicalize base type in member lookup
We would lose ParenType sugar in function types as a result.

Fixes part of <rdar://problem/29739905>.
2017-01-19 20:07:05 -08:00
Slava Pestov
140acd6a0d SILGen: Fix yet another 'argument labels ignored if parameter type is Any' thing
In Swift 3, we had a bug where you could provide argument labels
to a function call taking a single Any parameter, even if the
parameter did not have a label.

This mostly worked (with asserts off!) but in fact it would crash
in SILGen if you were calling an enum case constructor.

Since this 'feature' has been promoted from 'works on accident' to
'still a hack but guarded by Swift 3 mode and exists on purpose',
fix the crash, even though Swift 3 could not compile the code in
question.

Also add a Swift 3 mode check to the earlier SILGen hack, so that
when/if we remove Swift 3 mode it will be obvious that this code is
now dead too.
2017-01-19 17:27:45 -08:00
Slava Pestov
30c4235193 Sema: Horrific simulation of Swift 3 bug with argument labels for Swift 3 mode
In Swift 3.0.1, argument labels are ignored when calling a function
having a single parameter of 'Any' type. That is, if we have:

func foo(_: Any) {}

Both of the following were accepted in a no-assert build (an assert
build would crash, but the GM builds of Xcode ship with asserts off):

foo(123)
foo(data: 123)

This behavior was fixed by 578e36a7e1,
but unfortunately we have to revert to the old behavior *and* defeat
the assertion when in Swift 3 mode.

Swift 4 mode still has the correct behavior, where the second call
'foo(data: 123)' produces a diagnostic.

Now, I have to pour myself a strong drink to forget this ever happened.

Fixes <rdar://problem/28952837>.
2016-12-14 01:45:14 -08:00
Slava Pestov
dbb9d315e3 Sema: Fix a couple of crashes in tuple arguments tests
There's a general problem where a SubscriptExpr has an argument
that's a LoadExpr loading a tuple from an lvalue. For some reason
we don't construct the ParenExpr in this case, which confused
CSDiag.

Also, in Swift 3 mode, add a total hack to fudge things in
matchCallArguments() in the case where we erroneously lost
ParenType sugar.
2016-12-13 23:22:10 -08:00
Slava Pestov
3ede1ab205 Sema: New implementation of SE-0110
Fix matchTypes() to be more careful about stripping off ParenType
sugar, in order to match the behavior outlined in SE-0110.

Note that the new logic only executes in Swift 4 mode; there's
no functional change here in Swift 3 mode.

This makes a second copy of the tuple_arguments test:

- Compatibility/tuple_arguments is a test for Swift 3, updated to
  note differences with Swift 3.

- Constraints/tuple_arguments has been updated for the new Swift 4
  mode behavior.

Fixes <rdar://problem/27383557>.
2016-12-13 23:20:16 -08:00