[swift-users] Set-uniqueness of instances with distinct hashValue

milos at milos-and-slavica.net milos at milos-and-slavica.net
Sun Oct 23 04:24:58 CDT 2016

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?


More information about the swift-users mailing list