Generic curried function in Swift doesn’t capture the parameter

Originator:pavol.vaskovic
Number:rdar://19424740 Date Originated:09-Jan-2015 11:25 AM
Status:Closed Resolved:Fixed
Product:Developer Tools Product Version:Xcode 6.2 (6C101) Beta 3
Classification: Reproducible:always
 
Summary:
The generic function defined with curried function notation doesn’t capture the first parameter and appears to use some uninitialized(?) value, when invoked with arguments of type Double.

Steps to Reproduce:
Execute in playground or REPL: 

func curry<A, B, Z>(f: (A, B) -> Z)(_ a: A)(_ b: B) -> Z {
    println("a:\(a) b:\(b)")
    return f(a, b)
}

func quadratic(c: Double, z: Double) -> Double { return z * z + c }

quadratic(1, 2)

let q = curry(quadratic)
q(a: 1)(b: 2) // Should be 5!

let qc = q(a: 1)
qc(b: 2)  // Should be 5!

curry(quadratic)(a: 1)(b: 2) // correct

Expected Results:
Console output should be
a:1.0 b:2.0
a:1.0 b:2.0
a:1.0 b:2.0

Actual Results:
a:6.95075740882923e-310 b:2.0
a:6.95075741238967e-310 b:2.0
a:1.0 b:2.0

Version:
Version 6.2 (6C101) Beta 3

Notes:
Specialized definition of the curry function works correctly:

func curry(f: (Double, Double) -> Double)(_ a: Double)(_ b: Double) -> Double {
    println("a:\(a) b:\(b)")
    return f(a, b)
}

Comments

This issue has been verified as resolved in Xcode 6.3 beta 1 (6D520o) and can be closed.

By pavol.vaskovic at Feb. 25, 2015, 10:06 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!