Skip to content

Commit

Permalink
CLJS-1588: Self-host: satisfies? on defrecord instance
Browse files Browse the repository at this point in the history
A bit-shift operation for protocol
masks overflows to signed negagive
in JavaScript, causing bootstrap failure.

Fix is to simply multiply by 2 instead of
bit-shift left.
  • Loading branch information
mfikes authored and swannodette committed Apr 25, 2016
1 parent 8d33dd4 commit f110ed3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/main/clojure/cljs/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@
(iterate (core/fn [[p b]]
(if (core/== 2147483648 b)
[(core/inc p) 1]
[p (core/bit-shift-left b 1)]))
[p #?(:clj (core/bit-shift-left b 1)
:cljs (core/* 2 b))]))
[0 1])))

(def fast-path-protocol-partitions-count
Expand Down
6 changes: 5 additions & 1 deletion src/test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,9 @@
(defrecord C [a b c])
(defrecord A' [x])
(defrecord B' [x])
(defrecord FooComparable [x]
IComparable
(-compare [_ o] (compare x (.-x o))))

(deftest test-records
(let [fred (Person. "Fred" "Mertz")
Expand Down Expand Up @@ -1939,7 +1942,8 @@
(is (= (set (keys (dissoc more-letters :d))) #{:a :b :c :e :f}))
(is (= (set (keys (dissoc more-letters :d :e))) #{:a :b :c :f}))
(is (= (set (keys (dissoc more-letters :d :e :f))) #{:a :b :c}))
(is (not= (A'. nil) (B'. nil))))))
(is (not= (A'. nil) (B'. nil)))
(is (satisfies? IComparable (->FooComparable 1))))))

(deftype FnLike []
IFn
Expand Down

0 comments on commit f110ed3

Please sign in to comment.