hooman
(Hooman Mehr)
1
It seems that more specific function signatures are not selected when overloading on function arguments. For example:
let f = Double.advanced(by:) // Signature: (Double) -> (Double) -> Double
let g = Double.squareRoot // Signature: (Double) -> () -> Double
// Overloaded generic functions:
func test<T,U> (_ f: (T)->U ) { print("Chose (T)->U") }
func test<T,U> (_ f: (T)->()->U ) { print("Chose (T)->()->U") }
func test<T,U,V>(_ f: (T)->(U)->V ) { print("Chose (T)->(U)->V") }
test(f) // Prints: "Chose (T)->U"
test(g) // Prints: "Chose (T)->U"
Update: It turns out to be a bug in Xcode 9.2/Swift 4.0. It is fixed in Xcode 9.3/Swift 4.1.
Jens
2
I've run your code in Xcode 9.3 beta (in a Command Line App prj) and with both the default toolchain and the most recent dev snapshot, it prints:
Chose (T)->(U)->V
Chose (T)->()->U
What version of Swift are you using?
/Jens
hooman
(Hooman Mehr)
3
Interesting. I am getting this result on the current release version 9.2 (9C40b). I will try the beta to see what happens.
hooman
(Hooman Mehr)
4
Result of further testing:
Xcode 9.2 / Swift 4.0 exhibits this bug, but it seems to be fixed in Xcode 9.3 / Swift 4.1.