Swift Standard Library: Optional should NOT be Comparable

Originator:fabian.ehrentraud
Number:rdar://21459774 Date Originated:19-Jun-2015 03:26 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7 beta 1
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
Optionals can be compared via relational operators `<`, `<=`, `>` and `>=`. This leads to unexpected results.

Steps to Reproduce:
* `nil < 0` compiles and returns `true`.

Expected Results:
This should not even compile, as comparing .None to .Some via the given relational operators has no proper meaning.

Actual Results:
It compiles and might cover up a programming error.

Notes:
I would recommend removing the following methods from the Swift Standard Library:

func <<T : Comparable>(lhs: T?, rhs: T?) -> Bool
func <=<T : Comparable>(lhs: T?, rhs: T?) -> Bool
func ><T : Comparable>(lhs: T?, rhs: T?) -> Bool
func >=<T : Comparable>(lhs: T?, rhs: T?) -> Bool

Comments

What about making the return type of those a Bool?? It would return a value only when both Optionals are Some.


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!