Skip to content

Offer fix-its to disambiguate based on a trailing closure's label. #4777

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

Conversation

jrose-apple
Copy link
Contributor

(by making it a normal argument with a label and not a trailing closure)

Diagnostic part of rdar://problem/25607552. A later commit will keep us from getting in this situation quite so much when default arguments are involved.

This PR also sneaks in a new frontend option for compiler hackers, -verify-apply-fixes, to enable @lattner's auto-apply-fixes mode for -verify. That's not really the focus here, and I don't plan on cherry-picking that to the 3.0 branch.

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@nkcsgexi, @DougGregor, what do you think? @rintaro, are there any test cases I missed that came up when you were doing the rename fix-it?

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 201b431dfc419ab9ab60aa0d337055686ead54b9
Test requested by - @jrose-apple

@nkcsgexi
Copy link
Contributor

Cool stuff! I wish we had this before so that the migrator does not need to worry about ambiguity after renaming.

@jrose-apple
Copy link
Contributor Author

Yeah, unfortunately it happens after the migrator's already made its changes, so it can't just be auto-applied. But I figure you have good experience with these kinds of diagnostics by this point to be a good reviewer.

@jrose-apple jrose-apple force-pushed the fix-it-trailing-closure-ambiguity branch from 201b431 to ebca8ee Compare September 14, 2016 21:36
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@nkcsgexi
Copy link
Contributor

oh, You are right. We've no way to select which note's fixit to apply after wiping out the original code. I've briefly read the commit and it looks good to me.

@jrose-apple
Copy link
Contributor Author

Apple, Linux

@jrose-apple jrose-apple force-pushed the fix-it-trailing-closure-ambiguity branch from ebca8ee to 9424975 Compare September 14, 2016 23:29
@jrose-apple
Copy link
Contributor Author

Added one more diagnostic cleanup: 71b2bd39fae831a2b68f3cb115f3f0cd8e102a21. Would someone look over that too?

@jrose-apple
Copy link
Contributor Author

Previous tests passed, so I'm just going to smoke test the latest addition.

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

func overloadOnSomeDefaultArgsOnly2(_: Int, y: Bool = true, a: () -> Void) {} // expected-note {{found this candidate}}

func overloadOnSomeDefaultArgsOnly3(_: Int, x: Int = 0, a: () -> Void) {} // expected-note {{found this candidate}}
func overloadOnSomeDefaultArgsOnly3(_: Int, x: Bool = true, a: () -> Void) {} // expected-note {{found this candidate}}
Copy link
Member

@rintaro rintaro Sep 15, 2016

Choose a reason for hiding this comment

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

Fixing

overloadOnLabelSomeDefaultArgs(
  1, x: 2
) {
  // some
}

I prefer

overloadOnLabelSomeDefaultArgs(
  1, x: 2, a: {
  // some
})

than

overloadOnLabelSomeDefaultArgs(
  1, x: 2
, a: {
  // some
})

Edit: Sorry, wrong line for the comment. 😓

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. Should be doable. (And at some point it's probably worth factoring out "call-related source location utilities", but I'm hoping to cherry-pick this and want to keep it scoped.)

Enables Chris's auto-apply-fixes mode for -verify: if an expected-*
annotation has the wrong message, or if the expected fix-its are
incorrect, this option will **edit the original file** to update them.

This is a tool for compiler developers only; it doesn't affect
normal diagnostic printing or normal fix-its.
...unless the argument labels are the same for every possible
overload.

Only affects diagnostics.
(by making it a normal argument with a label and not a trailing
closure)

Diagnostic part of rdar://problem/25607552. A later commit will keep
us from getting in this situation quite so much when default arguments
are involved.
@jrose-apple jrose-apple force-pushed the fix-it-trailing-closure-ambiguity branch from 9424975 to e6d6e0e Compare September 15, 2016 18:05
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple jrose-apple merged commit 81284f5 into swiftlang:master Sep 15, 2016
@jrose-apple jrose-apple deleted the fix-it-trailing-closure-ambiguity branch September 15, 2016 20:03
@jrose-apple
Copy link
Contributor Author

Note: split into a separate Radar, rdar://problem/28325311, so that rdar://problem/25607552 can deal with the fact that many such calls shouldn't be ambiguous in the first place (because one of the overloads has default arguments and the other doesn't).

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.

4 participants