Fork me on GitHub
#cljs-dev
<
2018-01-22
>
mfikes12:01:00

Is recur across try supported in ClojureScript?

mfikes12:01:22

(and should arguably fail compilation as is done in Clojure)

dnolen14:01:47

@mfikes it shouldn’t work no

mfikes14:01:14

Cool. Fortunately, an extremely easy patch is possible by simply adding disallowing-recur.

mfikes14:01:19

I'm putting that together, and with three changes can catch all of these problematic cases

(loop [] (try (recur)))
(loop [] (try (catch js/Error t (recur))))
(loop [] (try (catch :default t (recur))))
(loop [] (try (finally (recur))))

dnolen14:01:01

k, with tests for those cases?

mfikes14:01:09

Yep, those are the test cases.

mfikes14:01:22

Wow. It caught something interesting:

(loop [] (binding [*foo* 1] (recur)))
This fails in Clojure and will also in ClojureScript because binding expands to try.

mfikes14:01:55

@dnolen With respect to this bit ^ about binding. We actually (incorrectly) use this construct here https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/js.cljs#L707 Would you prefer that a fix for that problematic recur be done as a separate patch, or combined with the one I'm putting together for https://dev.clojure.org/jira/browse/CLJS-2476 ?

dnolen14:01:25

@mfikes ok to fix that in the same patch