Skip to content

Commit 5e42603

Browse files
committed
CLJS-2787: Record comparison is broken when instance is constructed from another record instance via map factory
If map->Foo argument is a record, pour the extension map contents into a plain map
1 parent 3620434 commit 5e42603

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/clojure/cljs/core.cljc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,9 @@
18871887
ks (map keyword fields)
18881888
getters (map (core/fn [k] `(~k ~ms)) ks)]
18891889
`(defn ~fn-name ~docstring [~ms]
1890-
(new ~rname ~@getters nil (not-empty (dissoc ~ms ~@ks)) nil))))
1890+
(let [extmap# (cond->> (dissoc ~ms ~@ks)
1891+
(record? ~ms) (into {}))]
1892+
(new ~rname ~@getters nil (not-empty extmap#) nil)))))
18911893

18921894
(core/defmacro defrecord
18931895
"(defrecord name [fields*] options* specs*)

src/test/cljs/cljs/core_test.cljs

+7
Original file line numberDiff line numberDiff line change
@@ -1586,3 +1586,10 @@
15861586
(is (uri? (goog.Uri. "")))
15871587
(is (uri? (goog.Uri. "http://clojurescript.org")))
15881588
(is (uri? (goog.Uri. "some string")))))
1589+
1590+
(defrecord CLJS-2787 [])
1591+
1592+
(deftest test-cljs-2787
1593+
(let [x (map->CLJS-2787 {1 2})
1594+
y (map->CLJS-2787 x)]
1595+
(= x y)))

0 commit comments

Comments
 (0)