ClojureScript

Inconsistent hashing of empty collections

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    clojurescript 0.0-2496"
    clojure 1.6.0

Description

I get different results when hashing a literal empty vector than when hashing one from read-string, while all the other collections produce the same hash code:

``` clojure
homepage.core> [(hash [2]) (hash (cljs.reader/read-string "[2]"))]
[-1917711765 -1917711765]
homepage.core> [(hash [0]) (hash (cljs.reader/read-string "[0]"))]
[965192274 965192274]
homepage.core> [(hash []) (hash (cljs.reader/read-string "[]"))]
[0 -2017569654] ;; <--- this one looks suspicious.
homepage.core> [(hash {}) (hash (cljs.reader/read-string "{}"))]
[-15128758 -15128758]
homepage.core> (hash #{}) (hash (cljs.reader/read-string "#{}"))
[0 0]
homepage.core> clojurescript-version
"0.0-2496"
```

Activity

Hide
David Nolen added a comment -

Seems to be a bug that effects all empty collections, the hash values should match Clojure's.

Show
David Nolen added a comment - Seems to be a bug that effects all empty collections, the hash values should match Clojure's.
Hide
Michał Marczyk added a comment -

Patch with test.

Show
Michał Marczyk added a comment - Patch with test.
Hide
David Nolen added a comment -

Michal, wow thanks for the quick fix!

Show
David Nolen added a comment - Michal, wow thanks for the quick fix!
Hide
Michał Marczyk added a comment -

Thanks for the quick merge!

Show
Michał Marczyk added a comment - Thanks for the quick merge!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: