Skip to content

Commit 75e4e52

Browse files
borkdudeswannodette
authored andcommitted
CLJS-3023: Instrumenting next gives maximum call stack size exceeded
Use variation of next inside apply-to-simple.
1 parent ef56db9 commit 75e4e52

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,6 +3878,13 @@ reduces them without incurring seq initialization"
38783878

38793879
(set! *unchecked-if* true)
38803880

3881+
(defn- ^seq next*
3882+
"Internal. DO NOT USE! Next without the nil? check."
3883+
[coll]
3884+
(if (implements? INext coll)
3885+
(-next ^not-native coll)
3886+
(seq (rest coll))))
3887+
38813888
(defn- apply-to-simple
38823889
"Internal. DO NOT USE!
38833890
Assumes args was already called with seq beforehand!"
@@ -3886,25 +3893,25 @@ reduces them without incurring seq initialization"
38863893
(if (.-cljs$core$IFn$_invoke$arity$0 f)
38873894
(.cljs$core$IFn$_invoke$arity$0 f)
38883895
(.call f f))
3889-
(apply-to-simple f (-first args) (next args))))
3896+
(apply-to-simple f (-first args) (next* args))))
38903897
([f a0 ^seq args]
38913898
(if (nil? args)
38923899
(if (.-cljs$core$IFn$_invoke$arity$1 f)
38933900
(.cljs$core$IFn$_invoke$arity$1 f a0)
38943901
(.call f f a0))
3895-
(apply-to-simple f a0 (-first args) (next args))))
3902+
(apply-to-simple f a0 (-first args) (next* args))))
38963903
([f a0 a1 ^seq args]
38973904
(if (nil? args)
38983905
(if (.-cljs$core$IFn$_invoke$arity$2 f)
38993906
(.cljs$core$IFn$_invoke$arity$2 f a0 a1)
39003907
(.call f f a0 a1))
3901-
(apply-to-simple f a0 a1 (-first args) (next args))))
3908+
(apply-to-simple f a0 a1 (-first args) (next* args))))
39023909
([f a0 a1 a2 ^seq args]
39033910
(if (nil? args)
39043911
(if (.-cljs$core$IFn$_invoke$arity$3 f)
39053912
(.cljs$core$IFn$_invoke$arity$3 f a0 a1 a2)
39063913
(.call f f a0 a1 a2))
3907-
(apply-to-simple f a0 a1 a2 (-first args) (next args))))
3914+
(apply-to-simple f a0 a1 a2 (-first args) (next* args))))
39083915
([f a0 a1 a2 a3 ^seq args]
39093916
(if (nil? args)
39103917
(if (.-cljs$core$IFn$_invoke$arity$4 f)

src/test/cljs/cljs/spec/test_test.cljs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@
111111
(fn-2953 "abc"))))
112112
(is @#'stest/*instrument-enabled*))
113113

114-
(s/fdef cljs.core/= :args (s/+ any?))
115-
116114
(defn foo-2955 [n] "ret")
117115

118116
(s/fdef foo-2955
@@ -122,11 +120,14 @@
122120
(deftest test-cljs-2955
123121
(is (seq (stest/check `foo-2955))))
124122

123+
(s/fdef cljs.core/= :args (s/+ any?))
124+
125125
(deftest test-cljs-2956
126-
(stest/instrument 'cljs.core/=)
126+
(is (= '[cljs.core/=] (stest/instrument `=)))
127127
(is (true? (= 1)))
128-
(is (thrown? js/Error (=)))
129-
(stest/unstrument 'cljs.core/=))
128+
(is (thrown-with-msg?
129+
js/Error #"Call to #'cljs.core/= did not conform to spec\." (=)))
130+
(is (= '[cljs.core/=] (stest/unstrument `=))))
130131

131132
(defn fn-2975 [x])
132133

@@ -177,3 +178,11 @@
177178
:clojure.test.check/ret
178179
:num-tests)))
179180
check-res))))
181+
182+
(s/fdef cljs.core/next :args (s/cat :coll seqable?))
183+
184+
(deftest test-3023
185+
(is (= '[cljs.core/next] (stest/instrument `next)))
186+
(is (= [2 3] (next [1 2 3])))
187+
(is (thrown-with-msg? js/Error #"Call to #'cljs.core/next did not conform to spec\." (next 1)))
188+
(is (= '[cljs.core/next] (stest/unstrument `next))))

0 commit comments

Comments
 (0)