Skip to content

Commit

Permalink
CLJS-2787: Record comparison is broken when instance is constructed f…
Browse files Browse the repository at this point in the history
…rom another record instance via map factory

If map->Foo argument is a record, pour the extension map contents into
a plain map
  • Loading branch information
swannodette committed Jun 22, 2018
1 parent 3620434 commit 5e42603
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/clojure/cljs/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,9 @@
ks (map keyword fields)
getters (map (core/fn [k] `(~k ~ms)) ks)]
`(defn ~fn-name ~docstring [~ms]
(new ~rname ~@getters nil (not-empty (dissoc ~ms ~@ks)) nil))))
(let [extmap# (cond->> (dissoc ~ms ~@ks)
(record? ~ms) (into {}))]
(new ~rname ~@getters nil (not-empty extmap#) nil)))))

(core/defmacro defrecord
"(defrecord name [fields*] options* specs*)
Expand Down
7 changes: 7 additions & 0 deletions src/test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1586,3 +1586,10 @@
(is (uri? (goog.Uri. "")))
(is (uri? (goog.Uri. "http://clojurescript.org")))
(is (uri? (goog.Uri. "some string")))))

(defrecord CLJS-2787 [])

(deftest test-cljs-2787
(let [x (map->CLJS-2787 {1 2})
y (map->CLJS-2787 x)]
(= x y)))

0 comments on commit 5e42603

Please sign in to comment.