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-3702] Generic matching ignores function-type alternative in favor of non-function-type alternative #46287

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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3702
Radar None
Original Reporter bromine (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.0Regression, TypeChecker
Assignee @DougGregor
Priority Medium

md5: 6f7aea53970e5598c3e985ce953a1950

Issue Description:

Given declaration of (T) -> String and (() -> T) -> String, Swift 2 would choose the latter whereas Swift 3 chooses the former when a function argument is passed. Questions: is this intentional? Is this desirable? Is there a way to get Swift 2 behavior in Swift 3?

Example code:

func test<T>(_ x: T) -> String {
    return "From not-a-maker \(x)"
}

func test<T>(_ x: () -> T) -> String {
    return "From other maker \(x), producing \(x())"
}

func test(_ x: () -> String) -> String {
    return "From string maker \(x), producing \(x())"
}

func test(_ x: () -> Int) -> String {
    return "From int maker \(x), producing \(x())"
}

print("T str closure: \(test({"a"}))")
print("T int closure: \(test({1}))")
print("T float closure: \(test({1.0}))")

Swift 2 output:

T str closure: From string maker (Function), producing a
T int closure: From int maker (Function), producing 1
T float closure: From other maker (Function), producing 1.0

Swift 3 output:

T str closure: From not-a-maker (Function)
T int closure: From not-a-maker (Function)
T float closure: From not-a-maker (Function)
@belkadan
Copy link
Contributor

I have no idea what we changed here. @DougGregor?

@DougGregor
Copy link
Member

That's really odd. I don't know why this changed---the latter function should be considered "more specialized".

@swift-ci
Copy link
Collaborator Author

Comment by Ben Artin (JIRA)

Yeah, that's what I suspected. Thanks for confirming.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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 regression swift 3.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants