Swift: generic function does not seem to accept function type syntax

Originator:garth
Number:rdar://19524384 Date Originated:19-Jan-2015 03:11 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.2 (6C107a)
Classification:Serious Bug Reproducible:Always
 
I’m not 100% sure that I have the syntax correct here, but no variation seems to work either.

With this parenthesization, the compiler seems to accept the function header line, but it appears to be confused about the actual types involved.

The intent: given an item of type A and a sequence of functions that map type A to type B, return an array containing the Bs generated by the functions in the sequence.

func multiTransform<A, B, S: SequenceType where S.Generator.Element == ((A)->(B))>(seq: S, elt: A) -> [B] {
    var results = [B]()
    for xformFunc in seq {
        var xformed: B
        var foo: A->B = xformFunc  // Error: S.Generator.Element is not convertible to A->b
        xformed = xformFunc(elt)  // Error: '(A) -> $T3' is not identical to 'S.Generator.Element'
        results.append(xformFunc(elt))  // Error: '(A) -> $T5' is not identical to S.Generator.Element'
        
    }
    return results
}

Comments


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!