Set-uniqueness of instances with distinct hashValue

(Milos Rankovic) #1

Ah, one should never post to a mailing list before a morning coffee! The reason for the essentially undefined behaviour is that `Hashable` conformance must guarantee that two instances have the same `hashValue` if they are `==`, **but not vice versa**! In other words, the equality in the code snippet should've been implemented along the lines of:

     static func == (lhs: X, rhs: X) -> Bool {
         return lhs.hashValue == rhs.hashValue && lhs.x == rhs.x

Now, where is that coffee?