[Swift] Compiler segfaults when comparing optional enum with enum value

Originator:wirth_caesar
Number:rdar://19424210 Date Originated:09-Jan-2015
Status:Duplicate of 18841652 (Closed) Resolved:02-Apr-2015
Product:Developer Tools Product Version:Version 6.2 (6C86e)
Classification:Crash Reproducible:Always
 
It seems that the rules for implicitly unwrapping optional values within if conditions is inconsistent. 
In particular, if you have an Optional property enum type on an Optional object that you are comparing to the actual enum type. There is no warning thrown in Xcode, but the compiler crashes when trying to build. Syntactically it makes sense. It even works with Optional Bool values, so one would expect it to work elsewhere too.

class ServiceToken {
    enum Service: String {
        case Facebook = "facebook"
    }
    
    var service: Service?
    var flag: Bool?
}

class Test {
    func doThings() {
        /** Optional compred to enum value, and its OK **/
        var service: ServiceToken.Service?
        if service == .Facebook {
        }
        
        /** Optional on an object compared to an enum value, and its OK **/
        var token = ServiceToken()
        if token.service == .Facebook {
        }
        
        /*********************************/
        /** !This crashes the compiler! **/
        /*********************************/
        var maybeToken: ServiceToken?
        if maybeToken?.service == .Facebook {
        }
        
        /** Optional Bool on an optional object compared to a bool, and its OK  **/
        if maybeToken?.flag == true {
        }
    }
}


Version:
Version 6.2 (6C86e)
OS X 10.9.5 Build 13F34

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!