Testing the equality of two ImplicitlyUnwrappedOptionals should not unwrap them

Originator:brent
Number:rdar://20168340 Date Originated:15-Mar-2015 06:51 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (6D543q)
Classification:UI/Usability Reproducible:Always
 
Summary:
When you == two ImplicitlyUnwrappedOptionals, Swift unwraps them and uses their type’s equality operator. It should instead treat them like regular Optional types, comparing them in a nil-safe way.

Steps to Reproduce:
1. Write code like this in a Playground:

    let x: Int! = 1, y: Int! = nil
    x == y

Expected Results:
“false” in the timeline.

Actual Results:
EXC_BAD_INSTRUCTION because Swift tried to unwrap x and y to pass them to ==(Int, Int) -> Bool.

Notes:
While this isn’t *wrong* per se, it can be a nasty surprise. Providing something like the existing ==<T: Equatable>(Optional<T>, Optional<T>) -> Bool overload for IUOs, on the other hand, would yield safer behavior without changing any code that doesn’t currently crash.

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!