From f110ed3b0adcaad90912a3c89228cc882ffe2214 Mon Sep 17 00:00:00 2001 From: Mike Fikes Date: Sun, 24 Apr 2016 11:30:25 -0400 Subject: [PATCH] CLJS-1588: Self-host: satisfies? on defrecord instance 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. --- src/main/clojure/cljs/core.cljc | 3 ++- src/test/cljs/cljs/core_test.cljs | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/clojure/cljs/core.cljc b/src/main/clojure/cljs/core.cljc index 8ef2a3bb4b..d9da4618fa 100644 --- a/src/main/clojure/cljs/core.cljc +++ b/src/main/clojure/cljs/core.cljc @@ -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 diff --git a/src/test/cljs/cljs/core_test.cljs b/src/test/cljs/cljs/core_test.cljs index a6211735a9..aff60a69c0 100644 --- a/src/test/cljs/cljs/core_test.cljs +++ b/src/test/cljs/cljs/core_test.cljs @@ -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") @@ -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