-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…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.
@swift-ci please smoke test |
DougGregor
reviewed
Sep 25, 2019
There was a problem hiding this 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!
hborla
approved these changes
Sep 25, 2019
This was referenced Sep 26, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 extendMissingArgumentsFailure
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