Skip to content

Commit 7f3fd0f

Browse files
committed
CLJS-1518: Case macro expansion evaluates expression twice
Store the value of the case expression in a local.
1 parent 6e23244 commit 7f3fd0f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,8 @@
22292229
vec
22302230
(mapv #(if (seq? %) (vec %) [%])))
22312231
thens (vec (vals pairs))]
2232-
`(let [~esym (if (keyword? ~e) (.-fqn ~e) nil)]
2232+
`(let [~esym ~e
2233+
~esym (if (keyword? ~esym) (.-fqn ~esym) nil)]
22332234
(case* ~esym ~tests ~thens ~default)))
22342235

22352236
;; equality

src/test/cljs/cljs/core_test.cljs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,14 @@
11951195
(is (= x [1 2]))
11961196
(is (realized? x))))
11971197

1198+
(deftest test-1518
1199+
(testing "Test evaluate expression once - keyword tests"
1200+
(let [m {:a :b
1201+
:b :c}
1202+
x (atom :a)]
1203+
(case (swap! x m) :a 0 :default)
1204+
(is (= :b @x)))))
1205+
11981206
(comment
11991207
;; ObjMap
12001208
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)