ClojureScript

Case macro expansion evaluates expression twice

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: 1.7.145, 1.7.228
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    The issue is present in version 1.7.189.
  • Patch:
    Code and Test

Description

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))

Activity

Hide
Mike Fikes added a comment -

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.

Show
Mike Fikes added a comment - 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.
Hide
Mike Fikes added a comment - - edited

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))
Show
Mike Fikes added a comment - - edited 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))
Hide
António Nuno Monteiro added a comment -

Still present in 1.9.293.

Show
António Nuno Monteiro added a comment - Still present in 1.9.293.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: