Commit Graph

1143 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
1a57fc403a [ConstraintSystem] Make sure that l-value is preserved in argument positions
There is logic in `matchTypes` which would unwrap l-value if other
type is not an `inout`, which is not great for cases where parameter
type is a pointer and argument is an l-value which requires explicit
`&` to be converted.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
65c966ba16 [Diagnostics] Port a custom diagnostic for archetype mismatch in argument position 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
9d84aab2d5 [ConstraintSystem] Score generic argument-to-parameter mismatch fixes down
Since this is the most generic failure, we need to make sure that
it doesn't interfere with other more specific fixes.
2019-09-13 22:35:50 -07:00
Pavel Yaskevich
f28e674395 [Diagnostics] Detect situation when argument would match if it wasn't optional 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
0f24f7e05a [CSFix] Introduce a fix for argument-to-parameter conversion mismatch 2019-09-13 22:35:50 -07:00
Sasha Krassovsky
8cae17ceac Fix warnings in Sema 2019-09-13 09:57:48 -07:00
Slava Pestov
cd8fddd2df Merge pull request #27145 from slavapestov/refactor-type-check-checked-cast
Refactor typeCheckCheckedCast() and a few other things
2019-09-12 21:07:07 -04:00
Holly Borla
0434d58ff0 Merge pull request #27123 from hborla/missing-conformance-diag
[ConstraintSystem] Allow fixing missing conformance failures for `Void` and uninhabited types.
2019-09-12 17:41:19 -07:00
Slava Pestov
de4b63defc Sema: Refactor typeCheckCheckedCast() a bit
This removes all calls to typesSatisfyConstraint() except for the
isConvertibleTo() check at the beginning, in the process making the
analysis a little bit more accurate.
2019-09-12 16:37:53 -04:00
Doug Gregor
7882a97066 Merge pull request #27127 from DougGregor/dynamic-member-lookup-iwb-crash
[Type checker] Fix a crash triggered from index-while-building.
2019-09-11 20:51:51 -07:00
Doug Gregor
7151d0e3d7 [Type checker] Fix a crash triggered from index-while-building. 2019-09-11 14:28:35 -07:00
Holly Borla
b9367d10cf [ConstraintSystem] Allow fixing missing conformance failures for
`Void` and uninhabited types.
2019-09-11 12:10:19 -07:00
Hamish Knight
dafcaeb5eb [CS] Simplify getCalleeDeclAndArgs
Now that we associate argument labels for key path
subscript components, remove the special logic for
it. In addition, we can now search for callees
directly by using `getCalleeLocator`, as it should
now be able to find all the correct callees that
`getCalleeDeclAndArgs` does.

By using `getCalleeLocator`, we now also correctly
resolve callees for operator calls, meaning that
we can now use them with function builders. In
addition, we no longer incorrectly resolve callees
for calls made on SubscriptExprs.

Resolves SR-11439 & SR-11440.
2019-09-10 12:06:35 +01:00
Holly Borla
d1f139c345 Merge pull request #27043 from hborla/inout-attr-mismatch-diag
[Diagnostics] Extend the `AllowInOutConversion` fix to cover inout attribute mismatches in function types.
2019-09-05 15:14:46 -07:00
Holly Borla
7277f4f4ed [Diagnostics] Extend the AllowInOutConversion fix to cover inout attribute
mismatches in function types.

This improves the diagnostic in cases where we have argument-to-parameter
conversion failures or contextual type mismatches due to inout attribute
mismatches.
2019-09-05 14:16:24 -07:00
Slava Pestov
22cb6f1176 AST: Introduce ProtocolDecl::get{AssociatedType,ProtocolRequirement}() 2019-09-03 22:39:35 -04:00
Pavel Yaskevich
5291ffb919 Merge pull request #26996 from xedin/extend-use-of-invalid-generic-param
[ConstraintSystem] Extend `generic argument mismatch` fix to all pointer conversions
2019-09-03 15:06:36 -07:00
Pavel Yaskevich
e9aa04a91a [ConstraintSystem] Extend generic argument mismatch fix to all pointer conversions
This makes it possible to diagnose all implicit pointer
conversions in argument positions with a better error
message which preserves enclosing types, and allows to
share base type matching logic across all pointer conversions.
2019-09-02 19:08:00 -07:00
Hamish Knight
fdbc21911b [CS] Don't create new locator when simplifying to anchor
We can directly use the version of `simplifyLocator` that works on
an anchor and path array ref instead.
2019-09-02 18:09:47 +01:00
Suyash Srijan
bd53fe355d Revert "[CS] Don't crash when default argument is magic literal and types don't match" 2019-08-31 00:54:37 +01:00
Pavel Yaskevich
c16b888004 Merge pull request #26941 from xedin/req-failures-with-any
[Diagnostics] Treat type requirement failures associated with `Self` …
2019-08-30 12:30:09 -07:00
Suyash Srijan
9121f45256 Merge pull request #26944 from theblixguy/fix/SR-11394
[CSDiagnostics] Fix a crasher in MissingContextualConformanceFailure
2019-08-30 07:53:31 +01:00
Suyash Srijan
3eea861bbe [CSSimplify] Return failure if there are no elements in the path and the anchor does not point towards an AssignExpr 2019-08-30 01:48:44 +01:00
Suyash Srijan
86807acaa8 [CSSimplify] If the locator path is empty, then return failure 2019-08-30 00:38:34 +01:00
Pavel Yaskevich
ecf8146938 [Diagnostics] Treat type requirement failures associated with Self = Any as unrelated
This helps us to filter out cases like operator overloads where
`Self` type comes from e.g. default for collection element -
`[1, "hello"].map { $0 + 1 }`. Main problem here is that
collection type couldn't be determined without unification to
`Any` and `+` failing for all numeric overloads is just a consequence.
2019-08-29 15:27:29 -07:00