<< Back to previous view

[CLJS-1518] Case macro expansion evaluates expression twice Created: 21/Dec/15  Updated: 09/May/17  Resolved: 09/May/17

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: 1.7.145, 1.7.228
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Darrick Wiebe Assignee: David Nolen
Resolution: Completed Votes: 0
Labels: None

The issue is present in version 1.7.189.

Attachments: Text File CLJS-1518.patch    
Patch: Code and Test


The value being checked is evaluated twice if all of the test values are keywords.

(macroexpand-1 '(case (expensive) :a 1 2))
(cljs.core/let [G__123555 (if (cljs.core/keyword? (expensive)) (.-fqn (expensive)) nil)]
  (case* G__123555 [["a"]] [1] 2))

Comment by Mike Fikes [ 31/Jan/16 11:38 PM ]

Patch takes advantage of the existing gensym as a temp place to stash the evaluated value before test / FQN conversion.

Adds a unit test specifically checking for single evaluation in this case.

Comment by Mike Fikes [ 31/Jan/16 11:40 PM ]

With the patch, Darrick's macroexpansion example becomes:

(cljs.core/let [G__7663 (expensive) 
                G__7663 (if (cljs.core/keyword? G__7663) (.-fqn G__7663) nil)] 
  (case* G__7663 [["a"]] [1] 2))
Comment by António Nuno Monteiro [ 07/Nov/16 10:11 AM ]

Still present in 1.9.293.

Comment by David Nolen [ 09/May/17 8:20 AM ]

fixed https://github.com/clojure/clojurescript/commit/7f3fd0f3341cfdb3be0a9460842e08e9c79f264a

Generated at Sun May 19 12:00:18 CDT 2019 using JIRA 4.4#649-r158309.