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-6509] Incorrect resolving of ambigious initializers #49059

Closed
swift-ci opened this issue Nov 30, 2017 · 1 comment
Closed

[SR-6509] Incorrect resolving of ambigious initializers #49059

swift-ci opened this issue Nov 30, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6509
Radar None
Original Reporter TT_Kilew (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Tested on Swift version 4.0.1

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

md5: 113ccc05cc7b9c5abec81c7174801c92

Issue Description:

Consider this example

struct A {
    init<V>(value: V) {
        print("You passed value: " + "\(value)")
    }

    init<V>(_ action: () -> V) {
        print("You passed action: " + "\(action())")
    }
}
A { 42 }

// OUTPUT: You passed value: (Function)

Compiler will behave the same for non-generic class with generic initializer

class A {  // Not generic
    init<V>(value: V) {
        print("You passed value: " + "\(value)")
    }
    init(_ action: () -> Int) {   // Not generic
        print("You passed action: " + "\(action())")
    }
}
A { 42 }
// OUTPUT: You passed value: (Function)

Actual Results:

  • Compiler resolves V as closure (Function)

  • Compiler decides to apply trailing closure syntax rule

  • Compiler chooses `init(value: ()->Int)` and then it allows using trailing syntax by omitting value parameter

Expected Results

  • Compiler warns about potential ambiguous reference (Initializer cannot be determined)
@belkadan
Copy link
Contributor

The compiler should always pick the initializer with the more specific type, which in this case is the "action" one, rather than being ambiguous. You're right that the current behavior is broken; it seems to be fixed ("You passed action: 42") in master.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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
Projects
None yet
Development

No branches or pull requests

2 participants