close
The Wayback Machine - https://web.archive.org/web/20201125155227/https://github.com/apple/swift/pull/27362
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Diagnostics] Port missing argument(s) diagnostics #27362

Merged
merged 15 commits into from Sep 26, 2019
Merged

Conversation

@xedin
Copy link
Member

@xedin xedin commented Sep 25, 2019

Detect and fix missing arguments in diagnostic mode by synthesizing new arguments to either assume a parameter type or be defaulted to Any (which means that new arguments are always considered "holes" in constraint system) and extend MissingArgumentsFailure to diagnose single/multiple missing argument(s) as well as contextual mismatches.

Resolves: rdar://problem/55603016
Resolves: rdar://problem/54851719
Resolves: rdar://problem/31331436
Resolves: SR-3230
Resolves: SR-10126

xedin added 15 commits Sep 17, 2019
…nostic

Since we are about to start diagnosing more than just closures,
we need information about what synthesized arguments look like.
…dex 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.
Diagnose situation when parameter type expects N arguments
but argument has `M` where `M` < `N`, e.g.:

```swift
func foo(_: (Int) -> Void) {}
func bar() -> Void {}

foo(bar) // expected 1 argument, got 0
```
Function type has fewer arguments than expected by context:

```swift
func foo() {}
let _: (Int) -> Void = foo // expected 1 argument, got 0
```
… 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
```
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.
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.
@xedin xedin requested review from DougGregor and hborla Sep 25, 2019
@xedin
Copy link
Member Author

@xedin xedin commented Sep 25, 2019

@swift-ci please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

These diagnostic improvements look great, thanks!

@hborla
hborla approved these changes Sep 25, 2019
@xedin xedin merged commit 10b1bae into apple:master Sep 26, 2019
2 checks passed
2 checks passed
Swift Test Linux Platform (smoke test)
Details
Swift Test OS X Platform (smoke test)
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.