Commit Graph

251 Commits

Author SHA1 Message Date
Holly Borla
ef0ecc41e5 [ConstraintSystem] Diagnose missing AnyObject conformance using
the MissingConformance constraint fix.
2019-10-16 20:38:00 -07:00
Pavel Yaskevich
9913f8db27 [Diagnostics] NFC: Use isLastElement API instead of checking locator path 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
c97603f5d4 [CSDiagnostics] Diagnose extraneous arguments 2019-10-16 10:19:25 -07:00
Luciano Almeida
30ffe13cba Merge branch 'master' of https://github.com/apple/swift into force-downcast-fix-explicit-coercion 2019-10-13 11:09:37 -03:00
Luciano Almeida
d896968d2c clang-format 2019-10-12 22:39:12 -03:00
Luciano Almeida
f39ff88113 Initial implementation of moving the checks 2019-10-12 15:22:16 -03:00
Luciano Almeida
21c179d46f Removing fixed CoerceToCheckedCast constraint and letting repairFailures handle the diagnostics 2019-10-12 11:38:59 -03:00
Luciano Almeida
12f98d7922 Merge branch 'master' into force-downcast-fix-explicit-coercion 2019-10-06 13:35:44 -03:00
Hamish Knight
6e3671da41 Move FunctionArgApplyInfo up the header 2019-10-03 16:53:37 -07:00
Hamish Knight
b5a0d58dc0 Have ArgumentMismatchFailure store FunctionArgApplyInfo
And define members in order to allow the easy
access of relevant information about the failure.
2019-10-03 15:26:31 -07:00
Hamish Knight
12c1db9c93 NFC: Move ArgumentMismatchFailure down a bit
Just to make sure it's defined after
FunctionArgApplyInfo.
2019-10-03 15:08: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
Luciano Almeida
980ff05972 Add ForceDownCast fix for coercion expr to avoid fall-through into CSDiag 2019-10-01 20:25:15 -03:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -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
Pavel Yaskevich
cc2c868522 [Diagnostics] Produce a tailored diagnostic for multiple missing arguments 2019-09-24 22:05:14 -07:00
Robert Widmann
62266447f2 Drop the TypeChecker dependency from some helpers 2019-09-24 17:48:42 -07:00
Pavel Yaskevich
2120a31cf0 [Diagnostics] Correctly diagnose misplaced missing argument
Due to the fact that `matchCallArgument` can't and
doesn't take types into consideration while matching
arguments to parameters, when both arguments are
un-labeled, it's impossible to say which one is missing:

func foo(_: Int, _: String) {}
foo("")

In this case first argument is missing, but we end up with
two fixes - argument mismatch (for #1) and missing argument
(for #2), which is incorrect so it has to be handled specially.
2019-09-24 10:24:21 -07:00
Pavel Yaskevich
9406edc017 [Diagnostics] Tailored diagnostic for missing argument in property wrapper init 2019-09-23 13:00:37 -07:00
Pavel Yaskevich
60bcc94575 [Diagnostics] Implement single missing argument diagnosis
If call is missing a single argument we can provide a tailored
diagnostic and suggest a fix-it to add it at the appropriate
position.
2019-09-23 13:00:37 -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
4203c2f9f3 [Diagnostics] Store synthesized arguments in missing arguments diagnostic
Since we are about to start diagnosing more than just closures,
we need information about what synthesized arguments look like.
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
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
Holly Borla
29044e5d34 Merge pull request #27176 from hborla/type-cannot-conform-diag
[Diagnostics] Generalize the "protocol type cannot conform" error to work for all types that cannot conform to protocols.
2019-09-18 10:38:00 -07:00
Holly Borla
bf80250c84 Merge remote-tracking branch 'upstream/master' into type-cannot-conform-diag 2019-09-17 11:54:03 -07:00
Pavel Yaskevich
0aeaf7f15e [Diagnostics] NFC: Remove "trailing" from method name for closures with missing args
`MissingArgumentsFailure::diagnoseClosure` can actually diagnose both
closures in argument positions as well as when their type comes from
context e.g. `let _: (Int) -> Void = {}`.
2019-09-17 10:34:44 -07:00
Holly Borla
2a7e0099d2 [Diagnostics] Add notes for the type_cannot_conform error that point
to the declaration that requires protocol conformance.
2019-09-17 09:22:07 -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
Holly Borla
173e4526ee [Diagnostics] Adjust wording of type_cannot_conform error message. 2019-09-16 14:55:38 -07:00
Pavel Yaskevich
c20e4ac3c2 [Diagnostics] Fix usages of getChoiceFor 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
973d58d56f [Diagnostics] Provide a tailored diagnostic for operator mismatch on missing conformance
If missing conformance is between two stdlib defined types which
are used in operator invocation, let's produce a generic diagnostic
about operator reference and a note about missing conformance.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
90d725f701 [Diagnostics] Add special ambiguity diagnostics for operators
In cases when all of the fixed solutions have only one problem in
common - different overloads of a certain operator, let's
produce a tailored diagnostic and suggest matching partial
overloads along side diagnostic notes which point to each choice.
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
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
65c966ba16 [Diagnostics] Port a custom diagnostic for archetype mismatch in argument position 2019-09-13 22:35:50 -07:00
Pavel Yaskevich
34a12aa30e [Diagnostics] Add generic argument-to-parameter conversion failure
No specialized diagnostics yet, just a basic infrastructure to
produce generic a `cannot convert X to expected argument type Y`
message.
2019-09-13 22:35:50 -07:00
Hamish Knight
b9ad96a944 [CS] Add locator version of findSelectedOverloadFor 2019-09-10 12:06:35 +01:00
Hamish Knight
c745c17c38 Revert naming changes to getCalleeLocator & getChoiceFor
In addition, add a document comment to `getCalleeLocator` to clarify
its semantics.
2019-09-09 22:08:52 +01:00
Hamish Knight
dba850f16c [CSDiagnostics] Use getAnchormostCalleeLocator
Have FailureDiagnostic::getChoiceFor take a ConstraintLocator argument
which is passed through to getAnchormostCalleeLocator, and rename to
getAnchormostChoiceFor to make the semantics clear. In addition, add
a convenience getAnchormostChoice member for the common case of getting
the choice for the anchor of the failure's locator.

This change means we can now resolve callees for failures associated
with key path subscript components.

Resolves SR-11435.
2019-09-09 14:14:35 +01:00
Suyash Srijan
ab1184208a [CSDiagnostics] Offer a fix-it to conform the decl context to the missing protocols during contextual failure 2019-09-05 02:50:24 +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
b9cf4fa6c2 [Diagnostics] Add a diagnostic for invalid conversion of inout argument/parameter
Since there is no subtyping allowed in `inout` positions, let's
produce a tailored error message and a note about that.
2019-08-28 12:19:02 -07:00
Hamish Knight
86995f732f [CSDiagnostics] Add a couple of asserts to RequirementFailure
This will make it slightly easier to spot cases where we've resolved
to the wrong affected decl.
2019-08-27 15:59:08 +01:00
Pavel Yaskevich
b813976fd1 [Diagnostics] Port diagnostic for CTP_YieldByReference
Last special case from `FailureDiagnosis::diagnoseContextualConversionError`
has been ported to the new diagnostic framework.
2019-08-21 13:47:39 -07:00
Pavel Yaskevich
8296b554f4 [Diagnostics] Port tailored contextual diagnostic when thrown type doesn't conform to Error
`throw` statements are type-checked as having contextual `Error`
type to make sure that thrown type conforms to `Error` protocol.
Let's make sure that's correctly handled by new diagnostics framework.

```swift
func foo() throws {
  throw 0 // `Int` doesn't conform to `Error` protocol.
}
```
2019-08-20 17:03:19 -07:00
Pavel Yaskevich
0a8f596736 [Diagnostics] Port contextual mismatches involving nil to new framework
Detect and diagnose contextual failures originating in an attempt
to convert `nil` to some other non-optional type e.g.

```swift
let _: Int = nil // can't initialize `Int` with `nil`

func foo() -> Int {
  return nil // can't return `nil` from `foo`
}

_ = 1 + nil // there is no `+` overload which accepts `Int` and optional
```
2019-08-20 14:23:54 -07:00
Pavel Yaskevich
98a54a1e73 Merge pull request #26297 from hamishknight/pass-by-value-by-name
[CS] Add specific accessors for path element info
2019-08-20 01:04:59 -07:00
Pavel Yaskevich
7ac754acc4 [Diagnostics] Transform incorrect generic arguments into a contexual mismatch
Since this kind of failure is really a conversion failure, let's
inherit from `Contextual{Mismatch, Failure}` which also helps with
storage for from/to types and their resolution.

Also let's use original types involved in conversion to form
this fix, which helps to perserve all of the original sugar.
2019-08-19 09:56:48 -07:00