"Always fails" Casting Warning on Valid Casting (Casting Does Works)

Originator:slyfox7855
Number:rdar://23453982 Date Originated:11-07-2015
Status:Open Resolved:No
Product:Xcode Product Version:Xcode 7.1 and 7.2 beta
Classification:Other Bug Reproducible:Yes
 
Warning: Cast from `(T, T)` to unrelated type `(Float, Float)` always fails

Occurs when using pattern matching to check type of two items using a tuple.  The casting works as expected and does not always fail, so the warning is incorrect.  

Code below shows example case:

func SumNums<T:NumConvertible>( lhs:T,_ rhs:T) -> T {
    switch (lhs,rhs) {
        case let x as (Float, Float) :
            return T(x.0 + x.1)
        case let x as (Double, Double) :
            return T(x.0 + x.1)
        default:
            assert(false, "NumConvertible convert cast failed!")
            return T(0.0)
    }
}

public protocol NumConvertible:Equatable,Comparable{
    init(_ value: Float)
    init(_ value: Double)
}

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!