Skip to content

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

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

Merged
merged 15 commits into from
Sep 26, 2019

Conversation

xedin
Copy link
Contributor

@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

…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 swiftlang#1) and missing argument
(for swiftlang#2), which is incorrect so it has to be handled specially.
@xedin xedin requested review from DougGregor and hborla September 25, 2019 17:55
@xedin
Copy link
Contributor Author

xedin commented Sep 25, 2019

@swift-ci please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These diagnostic improvements look great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants