-
Notifications
You must be signed in to change notification settings - Fork 10.5k
When ranking overloads, always match up final closure parameters. #4785
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
When ranking overloads, always match up final closure parameters. #4785
Conversation
33e9428
to
2eba353
Compare
@DougGregor, @rudkx, this is a bit more interesting than a diagnostic change. This certainly allows programs that were previously ambiguous to compile, but can you think of any cases where it would change the meaning of existing programs, or take something that was previously accepted and make it an error (through ambiguity or something else)? @swift-ci Please test |
@jrose-apple I don't have an example in hand, but yes I think it might be possible to construct an example where after this change we would now consider something ambiguous where we wouldn't have previously. Consider something like We might have previously considered this unambiguous if there were two |
Drat. That sounds like this shouldn't go into a 3.0 point release then, and may need to be behind a version check when it does go in. I'll see if I can come up with a concrete case to add to the test suite. |
I'm having a very hard time writing such a test case in practice, which might mean we'll be able to put this into 3.1. Any ideas how I could trigger this behavior? // This example is accepted both with and without this patch.
class Ambiguity {
func ambiguous(x: Int = 0, _: () -> Void) {}
}
class SubAmbiguity: Ambiguity {
func ambiguous(_: () -> Void) {}
}
func orderedOverloads(_: Any) -> SubAmbiguity { return SubAmbiguity() }
func orderedOverloads(_: Int) -> Ambiguity { return Ambiguity() }
func testOrderedOverloads() {
orderedOverloads(0).ambiguous {}
} |
(in Swift 4 mode) There are a lot of other things that overload ranking does *not* take into account, and I intend to file a more general bug about that, but this should resolve some of the most egregious ambiguities with Swift 3's import rules (SE-0005, particularly "omit needless words" and adding default arguments). Finishes rdar://problem/25607552.
2eba353
to
27b4070
Compare
@swift-ci Please test |
Revived and limited to Swift 4 mode! |
Build failed |
@swift-ci Please test macOS |
Build failed |
@swift-ci Please test macOS |
Build failed |
@swift-ci Please test macOS |
Build failed |
@swift-ci Please test macOS |
@swift-ci Please test source compatibility |
Wait, hang on, I don't need to run that since I made the change in Swift 4 only. |
Looks good; I'm going to go ahead and merge |
There are a lot of other things that overload ranking does not take into account, and I intend to file a more general bug about that, but this should resolve some of the most egregious ambiguities with Swift 3's import rules (SE-0005, particularly "omit needless words" and adding default arguments).
Finishes rdar://problem/25607552. Depends on #4777 (well, not strictly, but that's how I structured the patch for now).
2eba353 is the thing to review here.