Skip to content

Commit f110ed3

Browse files
mfikesswannodette
authored andcommitted
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.
1 parent 8d33dd4 commit f110ed3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/main/clojure/cljs/core.cljc

+2-1
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@
755755
(iterate (core/fn [[p b]]
756756
(if (core/== 2147483648 b)
757757
[(core/inc p) 1]
758-
[p (core/bit-shift-left b 1)]))
758+
[p #?(:clj (core/bit-shift-left b 1)
759+
:cljs (core/* 2 b))]))
759760
[0 1])))
760761

761762
(def fast-path-protocol-partitions-count

Diff for: src/test/cljs/cljs/core_test.cljs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,9 @@
18991899
(defrecord C [a b c])
19001900
(defrecord A' [x])
19011901
(defrecord B' [x])
1902+
(defrecord FooComparable [x]
1903+
IComparable
1904+
(-compare [_ o] (compare x (.-x o))))
19021905

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

19441948
(deftype FnLike []
19451949
IFn

0 commit comments

Comments
 (0)