Swifters:
Take this simple Point type:
struct Point: Hashable {
let x: Int
let y: Int
init(_ x: Int, _ y: Int) {
self.x = x
self.y = y
}
}
Using the latest Swift 4.1 snapshot, the Hashable conformance is generated for
me. Adding Comparable conformance like this:
extension Point: Comparable {
static func < (lhs: Point, rhs: Point) -> Bool {
return (lhs.x < rhs.x && lhs.y <= rhs.y) || (lhs.x <= rhs.x && lhs.y
< rhs.y)
}
}
Once this is implemented, (0, 2) <= (1,1) bizarrely evaluates as true, despite
both < and == evaluating as false. Manually implementing <= fixes the issue.
static func <= (lhs: Point, rhs: Point) -> Bool {
return lhs < rhs || lhs == rhs
}
This is pretty straightforward code, so am I missing something here?
Jon
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users