Skip to content

Commit 6353a9b

Browse files
mfikesdnolen
authored andcommitted
CLJS-2948: Stack overflow calling instrumented variadic fn with zero args
1 parent 4fb83ef commit 6353a9b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/main/cljs/cljs/spec/test/alpha.cljs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,21 @@
105105
(str "Call to " v " did not conform to spec." )
106106
ed)))
107107
conformed)))
108+
pure-variadic? (and (-> (meta v) :top-fn :variadic?)
109+
(zero? (-> (meta v) :top-fn :max-fixed-arity)))
110+
apply' (fn [f args]
111+
(if (and (nil? args)
112+
pure-variadic?)
113+
(.cljs$core$IFn$_invoke$arity$variadic f)
114+
(apply f args)))
108115
ret (fn [& args]
109116
(if *instrument-enabled*
110117
(with-instrument-disabled
111118
(when (:args fn-spec) (conform! v :args (:args fn-spec) args args))
112119
(binding [*instrument-enabled* true]
113-
(apply f args)))
114-
(apply f args)))]
115-
(when-not (and (-> (meta v) :top-fn :variadic?)
116-
(zero? (-> (meta v) :top-fn :max-fixed-arity)))
120+
(apply' f args)))
121+
(apply' f args)))]
122+
(when-not pure-variadic?
117123
(setup-static-dispatches f ret 20)
118124
(when-some [variadic (.-cljs$core$IFn$_invoke$arity$variadic f)]
119125
(set! (.-cljs$core$IFn$_invoke$arity$variadic ret)

src/test/cljs/cljs/spec_test.cljs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@
387387
(st/instrument `foo-2793)
388388
(st/instrument `bar-2793)
389389
(st/instrument `baz-2793)
390+
(st/instrument `quux-2793)
390391

391392
(deftest cljs-2793-test
392393
(is (= {:m {:x 1 :y 2}
@@ -411,7 +412,8 @@
411412
:y 2
412413
:m [3 4]}
413414
(bar-2793 1 2 3 4)))
414-
(is (nil? (baz-2793 1))))
415+
(is (nil? (baz-2793 1)))
416+
(is (nil? (quux-2793))))
415417

416418
(comment
417419

0 commit comments

Comments
 (0)