Skip to content
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

[SR-11572] Don't get "Ambiguous use of 'function name'" for 2 functions with the same name but different arguments list #53977

Open
swift-ci opened this issue Oct 5, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Oct 5, 2019

Previous ID SR-11572
Radar None
Original Reporter RomanPodymov (JIRA User)
Type Bug
Environment

Xcode 11, Swift 5.1.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 1f6a51466992eb996ce8078af2861425

Issue Description:

Consider the following declaration:

protocol P {
    associatedtype T   
    func f(arg: T)
}
 
struct S: P {
    func f(arg: Void) { }
}

func f<T: P>(some args: T ...) where T.T == Void { }

func f<T: P, K: P>(some arg1: T, _ arg2: K) { }

Then I call f(some: S(), S()) and this code is compilable. But I think I should get "Ambiguous use of 'f'" on this line. And I get this error when add the following declaration:

func f(another arg1: S, _ arg2: S) { }
@swift-ci
Copy link
Collaborator Author

swift-ci commented Oct 5, 2019

Comment by Owen Voorhees (JIRA)

RomanPodymov (JIRA User) In practice, the second overload of `f` with two generic parameters will be called. This is definitely confusing, but is the expected behavior. When Swift decides which function named `f` to call, it will always chose the most specific one which can be used in the current context. In this case, both functions could be used, but a function with a fixed number of parameters will always be chosen before one with a variadic parameter according to swift's ranking rules.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Oct 5, 2019

Comment by Roman Podymov (JIRA)

Hello owenvoorhees (JIRA User)

I updated the issue.

@LucianoPAlmeida
Copy link
Collaborator

Just linking to the discussion for future reference #30567 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants