Open
Description
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)