(This question arises from a discussion at http://stackoverflow.com/questions/33216358/swift-operators-and-nil.)
Optionals can be compared if the underlying wrapped type is comparable:
public func <<T : Comparable>(lhs: T?, rhs: T?) -> BoolBut this compiles as well:
func foo(x : Int?, _ y : Int) {
let b = x < y
print(b)
}and it seems that the Int on the rhs is "auto-wrapped* into Optional<Int>, using the init method
/// Construct a non-`nil` instance that stores `some`.
public init(_ some: Wrapped)But why? The Swift book clearly states that "Values are never implicitly converted to another type." Also in other cases, like comparing Int and Double, no auto-wrapping from Int to Double or vice versa is done. I am probably missing something obvious, but I cannot see from the Swift documentation why this works in the case of optionals.