Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[Diagnostics] Port missing argument(s) diagnostics #27362
Conversation
…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.
|
@swift-ci please smoke test |
|
These diagnostic improvements look great, thanks! |


Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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 extendMissingArgumentsFailureto 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