Commit Graph

1168 Commits

Author SHA1 Message Date
Pavel Yaskevich
22813d96cf [ConstraintSystem] Extend MatchCallArgumentListener::extraArguments to return all extraneous arguments 2019-10-16 10:19:25 -07:00
Pavel Yaskevich
f1ed46ee82 [CSFix] Add a fix to remove extraneous arguments
If there are more arguments than parameters, let's fix this by
ignoring (if possible) or removing extraneous arguments. Ignored
arguments could default to `Any` if they don't get any other
contextual type.
2019-10-16 10:19:25 -07:00
Hamish Knight
fc020bb3f4 [CS] Add ConstraintSystem::addFixConstraint
This lets us add a constraint to the system with an associated fix.
Unlike `addUnsolvedConstraint`, this will attempt to immediately
simplify the constraint, producing an unsolved constraint if necessary.
2019-10-15 10:12:48 -07:00
Hamish Knight
9d21fbb445 [CS] Don't try inout-to-ptr for array to raw ptr
Array-to-pointer should only be used for such conversions. This isn't
currently an issue as we short-circuit disjunctions upon successfully
solving an array-to-pointer conversion. However this would become an
issue if only inout-to-pointer was viable.
2019-10-15 10:12:48 -07:00
Hamish Knight
2759ae29bb [AST] Add TypeBase::lookThroughSingleOptionalType 2019-10-15 10:12:48 -07:00
Robert Widmann
f15544de0b Strike VarDecls in Pattern Binding Initializers From Overloads
We would previously consider the VarDecls bound by a particular pattern
binding initializer context when performing overload resolution.  This
would lead to circular validation.  Validation was tacitly breaking the
cycle by returning an error type (but, crucially, not setting that
interface type).  Instead, pre-reject circular candidates.

This greatly improves the diagnostic we emit here in truly circular
cases since we can ride on `UR_InstanceMemberOnType` to yield

struct PatternBindingWithTwoVars2 { var x = y, y = 3 }
// cannot use instance member 'y' within property initializer; property initializers run before 'self' is available
2019-10-14 11:54:24 -07:00
swift-ci
7d437ec4a8 Merge pull request #27629 from DougGregor/builder-refactoring-prelude 2019-10-11 15:35:11 -07:00
Pavel Yaskevich
6b9b764974 Merge pull request #27614 from xedin/inout-type-mismatch
[ConstraintSystem] Detect and diagnose type mismatch failures of `ino…
2019-10-11 14:14:09 -07:00
Doug Gregor
eb61ae7971 [Type checker] Factor out ConstraintSystem::addJoinConstraint().
Use it for ternary expressions; it'll gain other clients soon.
2019-10-11 10:07:21 -07:00
Pavel Yaskevich
1846a5957e Merge pull request #27608 from xedin/autoclosure-ctx-mismatch
[Diagnostics] Extend use of argument mismatch fix to `autoclosure` pa…
2019-10-11 02:10:27 -07:00
Pavel Yaskevich
773ac24bc9 [ConstraintSystem] Detect and diagnose type mismatch failures of inout parameters
Currently absence of `subtyping` is the only problem detected and diagnosed specifically
for `inout` parameters, but there could be type mismatches in `inout` positions as well
 and we can use `argument-to-parameter mismatch fix to detect and diagnose them.
2019-10-10 17:06:13 -07:00
Pavel Yaskevich
f09b07be6c [Diagnostics] Extend use of argument mismatch fix to autoclosure parameters
When it comes to `@autoclosure` parameters we only detect and diagnose
mismatches related to invalid implicit conversions to pointer types. But
`@autoclosure` parameters just like regular ones can have type mismatches
as well which can be handled via recently introduced
`argument-to-parameter mismatch` fix.
2019-10-10 13:33:23 -07:00
Brent Royal-Gordon
987b2c96bb Merge pull request #27593 from brentdax/dissolved-in-a-solution
Fix SE-0249 source compatibility break
2019-10-09 21:43:07 -07:00
Brent Royal-Gordon
932128eab6 Fix SE-0249 source compatibility break
In some situations where both the KeyPath and closure solutions for an expression with a keypath literal were valid, the type checker could not choose between them and Swift would emit an “ambiguous use” error. This change increase the typechecking score of the closure solution so that the typechecker will favor the KeyPath solution, preserving source compatibility for existing APIs.

Fixes rdar://problem/56131416.
2019-10-09 17:17:41 -07:00
Hamish Knight
ec45b24b63 Use hasAppliedSelf in getFunctionArgApplyInfo
`callee->hasCurriedSelf()` isn't the correct check
here when we have an argument mismatch for the
self parameter in a curried application.
2019-10-03 15:26:31 -07:00
Hamish Knight
c108dae5d9 [CSDiagnostics] Find argument lists for key path subscripts
This commit changes `getArgumentExprFor` to take
a ConstraintLocator argument from which to find
the argument list. This lets us properly handle
the case where we have a key path subscript
locator. In addition, this commit renames the
member to `getArgumentListExprFor` to make it
clear we're returning the argument list expression
rather than a single argument.

Resolves SR-11562.
2019-10-02 08:00:14 -07:00
Hamish Knight
6d8b798789 [CS] Have isLastElement take a locator path elt class
This makes it consistent with `getLastElementAs`
and `castLastElementTo`.
2019-09-29 14:19:56 -07:00
Pavel Yaskevich
6aadbc3d52 Merge pull request #27390 from xedin/sr-11491
[Diagnostics] Centralize requirement failure impact assessment
2019-09-27 19:39:36 -07:00
Pavel Yaskevich
24a5003078 [ConstraintSystem] Materialize locator only once per missing argument
Instead of materializing locator twice from the same builder per
missing argument, do it only once and use result to create argument
type variable and its "defaults to Any" constraint.
2019-09-26 20:48:49 -07:00
Pavel Yaskevich
694023ac7c [Diagnostics] Centralize requirement failure impact assessment
Conformance requirements get their fixes attached directly where
other requirements have to use (for now) `repairFailure` mechanism.

Regardless of _how_ fixes get recorded there should be a single
way to assess impact of a particular requirement failure.

The rules are:

- If this is a requirement associated with an operator, impact
  is based on use of the type which failed the requirement;

- If this requirement is from conditional extension,
  it is considered a very high impact because failing such
  requirement makes referenced member de facto invisible.

Resolves: rdar://problem/55593998
Resolves: [SR-11491](https://bugs.swift.org/browse/SR-11491)
2019-09-26 12:13:06 -07:00
Pavel Yaskevich
10b1baebb2 Merge pull request #27362 from xedin/port-missing-args
[Diagnostics] Port missing argument(s) diagnostics
2019-09-25 21:08:54 -07:00
Slava Pestov
b1ffa19c7b AST: Refine recursive property checks on type alias types 2019-09-24 17:39:53 -04:00
Pavel Yaskevich
a3e26abd8a [ConstraintSystem] Mark each of the synthesized arguments as a "hole" 2019-09-24 11:00:57 -07:00
Robert Widmann
3e48f71b27 Merge pull request #27314 from CodaFi/an-interface-to-the-interface
Requestify getInterfaceType() in Name Only
2019-09-23 22:35:24 -07:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Pavel Yaskevich
73b6427f64 [ConstraintSystem] Store parameter flags in synthesized argument locator 2019-09-23 14:19:29 -07:00
Pavel Yaskevich
ee8c78eef5 [Diagnostics] Tailored diagnostic when single tuple used instead of N distinct arguments
Diagnose cases when instead of multiple distinct arguments
call got a single tuple argument with expected arity/types:

```swift
func foo(_: Int, _: Int) {}
foo((0, 1)) // expected 2 arguments, got 1 tuple with 2 elements
```
2019-09-23 13:00:37 -07:00
Pavel Yaskevich
b8528cd575 [ConstraintSystem] Short-circuit matching if missing arguments have been synthesized 2019-09-23 13:00:37 -07:00
Pavel Yaskevich
65c03d5f06 [ConstraintSystem] Allow solver to synthesize missing arguments in diagnostic mode 2019-09-23 13:00:37 -07:00
Pavel Yaskevich
b15ef15a60 [ConstraintSystem] Change missingArgument callback to produce an index of synthesized argument
In diagnostic mode allow argument matcher to synthesize new
arguments, which makes it much easier to diagnose problems
related to missing arguments.
2019-09-23 12:59:27 -07:00
Pavel Yaskevich
96598d8ebf Merge pull request #26207 from owenv/new-vararg-conversion-diag
[Diagnostics] Improve diagnostic when attempting to pass an Array to a variadic argument
2019-09-23 12:57:44 -07:00
Robert Widmann
b135928125 Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless.  All of the callers intended to ask "hasInterfaceType" anyways.
2019-09-20 22:22:49 -07:00
Owen Voorhees
6c5185f2e3 Improve diagnostic when attempting to pass an Array to a variadic argument
- Give a more specific diagnostic which indicates the parameter is variadic
- If the argument is an Array literal, offer to drop the brackets
2019-09-20 17:30:23 -07:00
Pavel Yaskevich
8eaeb51fe5 [ConstraintSystem] Introduce a fix for assignment type mismatch
Introduce a fix/diagnostic when there is a contextual mismatch
between source and destination types of the assignment e.g.:

```swift
var x: Int = 0
x = 4.0 // destination expects an `Int`, but source is a `Double`
```
2019-09-20 17:12:04 -07:00
Pavel Yaskevich
c968c14a24 [Diagnostics] Cover single explicit tuple argument -> N parameters via missing arguments fix
Expand tuple into N arguments to cover expect parameters.

This covers cases like this:

```swift
func foo(_: (Int, Int) -> Void) {}
foo { (bar: (Int, Int)) in } // used a single tuple type `(Int, Int)`
                             // instead of two distinct arguments
```
2019-09-17 00:27:17 -07:00
Pavel Yaskevich
2f325fa1d8 [Diagnostics] Don't store contextual type in missing argument fix/diagnostic
Instead of storing contextual function type in the fix/diagnostic,
let's fetch it from context (solution and/or locator) because it's
only used when it is a trailing closure missing some arguments anyway.
2019-09-16 16:50:31 -07:00
Pavel Yaskevich
1cd1f259e0 [ConstraintSystem] NFC: Fix typo implact -> impact 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
afc3408b60 [ConstraintSystem] De-prioritize missing member fix when base is contextual
Impact is higher if the base is expected to be inferred from context,
because a failure to find a member ultimately means that base type is
not a match in this case.
2019-09-13 22:35:53 -07:00
Pavel Yaskevich
c20e4ac3c2 [Diagnostics] Fix usages of getChoiceFor 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
26e51e0e43 [ConstraintSystem] Fix: Try to match argument to element type if parameter is a collection
This allows better diagnostics in cases where collection element
is a generic parameter which is supposed to be inferred from argument e.g.

```swift
func foo<T>(_: [T]) {}

foo(1) // Missing brackets, so error should be about [Int] vs. Int
```
2019-09-13 22:35:53 -07:00
Pavel Yaskevich
b0299f7066 [CSSimplify] NFC: Adjust comment about matching dependent types with invalid base 2019-09-13 22:35:53 -07:00
Pavel Yaskevich
b898eaf326 [Diagnostics] Tailored diagnostics for reference equality operator mismatches 2019-09-13 22:35:52 -07:00
Pavel Yaskevich
25d7a07323 [ConstraintSystem] Adjust a couple of places not to fail immediately in diagnostic mode
Some spots of constraint simplification logic are too eager to
fail right away without giving repair logic to run in diagnostic
mode and attempt to fix the problem. Failing early in diagnostic
mode means solver wouldn't be able to reach some possible
solutions which leads to subpar diagnostics.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
df8d1a078a [ConstraintSystem] Fail comparison if dependent member types couldn't be resolved
Currently in cases where dependent member types cannot be resolved
properly due to invalid base type they do not fail comparison, but
instead result in a new "inactive" constraint which is incorrect.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
015129cb36 [Diagnostics] Allow requirement failure to diagnose operators
In absence of general argument conversion failures requirement
errors associated with operators couldn't be diagnosed properly,
now this restriction could be lifted.
2019-09-13 22:35:51 -07:00
Pavel Yaskevich
79606619a7 [ConstraintSystem] Lift restriction which restricted conformance fixes in argument positions
If argument doesn't conform to the protocol expected by the parameter
let's add argument conversion mismatch fix for that with increased impact.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
446d0f84f4 [ConstraintSystem] Rate impact of conformance failures based on non-conforming type use
Impact of conformance failure should be rated based on use of
associated generic parameter, because a single failure could
span multiple parameters and a result.

Originally score was only increased once for conformance failure.
That is not good enough in cases when conformance is associated
with an overload choice, because in that case we can have an argument
mismatch in other choice which would have the same score impact.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
953b9f74aa [ConstraintSystem] Fix a situation when argument requires raw representable type 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
c946b3862e [ConstraintSystem] Don't produce argument mismatch fix when pointer conversions are involved 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
93b39c9c23 [Diagnostics] Port pattern-matching mismatch diagnostic
Port diagnostics associated with implicit use of `~=` operator
which is used in `case` statements.
2019-09-13 22:35:50 -07:00