squint-cljs / cherry

Experimental ClojureScript to ES6 module compiler
https://squint-cljs.github.io/cherry
558 stars 22 forks source link

Invalid arity issue when wrapping a macro around twenty expressions #78

Closed alexdao3 closed 2 years ago

alexdao3 commented 2 years ago

https://clojurians.slack.com/archives/C03QZH5PG6M/p1668017779830469

I have the following do! macro that wraps individual exprs in js/await. When I have greater than ~20 expressions in the body of the do!, the compiler throws an error

(defmacro do!
  [& exprs]
  `(do
     ~@(map (fn [expr#] `(js/await ~expr#)) exprs)))

;; usage
(do!
  (first-async-fn)
  ...
  (twentieth-async-fn))
file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cli.js:483
arguments[18],arguments[19],arguments[20],arguments[21]);default:throw Error(["Invalid arity: ",$APP.v.h(arguments.length-1)].join(""));}};$APP.g.apply=function(a,b){return this.call.apply(this,[this].concat($APP.ib(b)))};$APP.g.v=function(){var a=$APP.w(this);return a.v?a.v():a.call(null)};$APP.g.h=function(a){var b=$APP.w(this);return b.h?b.h(a):b.call(null,a)};$APP.g.g=function(a,b){var c=$APP.w(this);return c.g?c.g(a,b):c.call(null,a,b)};

Error: Invalid arity: 23
    at VQ.$APP.g.call (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cli.js:483:72)
    at VQ.$APP.g.apply (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cli.js:483:184)
    at Xg (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cljs_core.js:551:491)
    at Wg (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cljs_core.js:547:70)
    at Ug (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cljs_core.js:546:421)
    at Function.$APP.Ch.B (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/cljs_core.js:793:404)
    at file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/compiler.js:587:258
    at file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/compiler.js:588:267
    at $APP.kr.$APP.g.g (file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/compiler.js:213:289)
    at file:///Users/alex/code/icebreaker/ui_tests/node_modules/cherry-cljs/lib/compiler.js:185:206

I'm able to work around this issue by wrapping a subset of the expressions (to get under ~20) into their own functions and invoking them i.e.

(do!
  (^:async (fn []
    (do!
      (first-async-fn)
      ...
      (tenth-async-fn)))
  (^:async (fn []
      (eleventh-async-fn)
      ...
      (twentieth-async-fn)))))