[swift-users] generic function called recursively not compiling

Ray Fix rayfix at gmail.com
Thu Aug 4 11:02:34 CDT 2016


I filed rdar://27700622 <rdar://27700622> and attached a playground.  Any workaround magic I can do here?

func quickSort<Element: Comparable>(_ input: [Element]) -> [Element] {
    if input.count < 2 {
        return input
    }
    let pivot = input.first!
    let left = input.dropFirst().filter { $0 <= pivot }
    let right = input.dropFirst().filter { $0 > pivot }

    // Does not compile with (Swift 3pre) Xcode 8 b1,2,3,4
    // Does compile with (Swift 2.2) Xcode 7.3
    return quickSort(left) + [pivot] + quickSort(right)
}

quickSort([3,5,1,2])

Error:
//Playground execution failed: error: quicksort.playground:11:22: error: cannot convert value of type '[Element]' to expected argument type '[_]'
//return quickSort(left) + [pivot] + quickSort(right)
//                 ^~~~


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160804/ff9cf828/attachment.html>


More information about the swift-users mailing list