Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

user=> (case -1 -1 true false) true user=> (case [-1] [-1] true false) true user=> (case (int -1) -1 true false) true user=> (case [(int 1)] [1] true false) true user=> (case [(int -1)] [-1] true false) false

The last case should return true like the other,

Real life example that triggered this:

(case [">" (compare 2 3)] [">" -1] true false) ;; false?

Explaination: This is caused by case using hashCode instead of hashEq for hash comparisons (when not wrapped in a vector, the comparison is direct) and the fact that negative integers and negative longs hash differently while positive ones hash identical.
Porposal: Make case use hasheq instead of hashCode

Patch: 0001-switch-to-hasheq-for-case.patch

2 Answers

0 votes
by

Comment made by: bronsa

Patch is a straightforward search and replace, apart from line 30 of the diff which is quite tricky: I believe using h there was a bug in the previous impl that never survaced because hashCode on positive integers is idempotent. But since hashEq isn't double hashing would cause collision nodes never to match.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2275 (reported by alex+import)
...