Skip to content

Commit e024283

Browse files
anmonteirodnolen
authored andcommitted
CLJS-1818: (hash false) returns different value from Clojure
mirrors Clojure's and JVM's behavior of returning fixed prime numbers as the hashCode of true and false. http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#hashCode%28%29
1 parent f826c31 commit e024283

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,12 @@
902902
-1048576
903903
2146959360))
904904

905-
(true? o) 1
905+
;; note: mirrors Clojure's behavior on the JVM, where the hashCode is
906+
;; 1231 for true and 1237 for false
907+
;; http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#hashCode%28%29
908+
(true? o) 1231
906909

907-
(false? o) 0
910+
(false? o) 1237
908911

909912
(string? o)
910913
(m3-hash-int (hash-string o))

src/test/cljs/cljs/hashing_test.cljs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@
8787
(is (== (imul -2 -2) 4))
8888
(is (== (imul 0xffffffff 5) -5))
8989
(is (== (imul 0xfffffffe 5) -10))
90-
))
90+
))
91+
92+
(deftest test-cljs-1818
93+
(is (= (hash true) 1231))
94+
(is (= (hash false) 1237)))

0 commit comments

Comments
 (0)