Skip to content

Commit 05952c3

Browse files
committed
Handle false vs nil in sets
1 parent 6977ad7 commit 05952c3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/flatland/ordered/set.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
(toString [this]
5757
(str "#{" (clojure.string/join " " (map str this)) "}"))
5858
(hashCode [this]
59-
(reduce + (keep #(when % (.hashCode ^Object %)) (.seq this))))
59+
(reduce + (keep #(when (some? %) (.hashCode ^Object %)) (.seq this))))
6060
(equals [this other]
6161
(or (identical? this other)
6262
(and (instance? Set other)

test/flatland/ordered/set_test.clj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@
165165
(is (= (.hashCode (ordered-set nil)) (.hashCode (hash-set nil))))
166166
(is (= (.hashCode (ordered-set nil :a {:b nil})) (.hashCode (hash-set nil :a {:b nil}))))))
167167

168+
(deftest nil-and-false-hashes
169+
(is (not= (.hashCode (ordered-set nil)) (.hashCode (hash-set false))))
170+
(is (not= (.hashCode (ordered-set false)) (.hashCode (hash-set nil))))
171+
(is (= (.hashCode (ordered-set false nil)) (.hashCode (hash-set nil false)))))
172+
168173
(deftest nil-hash-code-npe
169174
;; No assertions here; just check that it doesn't NPE
170175
;; See: https://github.com/amalloy/ordered/issues/27

0 commit comments

Comments
 (0)