Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Records of different types with the same data have the same hashcodes, even though they are not considered to be equal
Key details
Description
Records which contain the same field values are not considered to be equal, but the record type is not currently included in the hash. This means that if an heterogenous map contains records of different types, where the fields aren't necessarily distinct, there is a high likelyhood of hash collisions.
I propose that the record type should be included in the hash code algorithm for records. There should be no expectation that unequal records of different types should have the same hash-code.
Records which contain the same field values are not considered to be equal, but the record type is not currently included in the hash. This means that if an heterogenous map contains records of different types, where the fields aren't necessarily distinct, there is a high likelyhood of hash collisions.
I propose that the record type should be included in the hash code algorithm for records. There should be no expectation that unequal records of different types should have the same hash-code.
user=> (hash (->A 1))
1013911913
user=> (hash (->B 1))
1013911913
user=> (= (>A 1) (>B 1))
false
This issue also affects ClojureScript. But see [#CLJS-97], as ClojureScript also has an issue with record equality.