Skip to content

Commit 5fb8ca8

Browse files
vspinubbatsov
authored andcommitted
Fix instrumentation of recursive functions
1 parent b13881e commit 5fb8ca8

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

src/cider/nrepl/middleware/util/instrument.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@
161161
:else form))))
162162

163163
(defn- contains-recur?
164-
"Return true if form is not a `loop` and a `recur` is found in it."
164+
"Return true if form is not a `loop` or a `fn` and a `recur` is found in it."
165165
[form]
166166
(if (seq? form)
167167
(case (first form)
168168
recur true
169169
loop* false
170+
fn* false
170171
(some contains-recur? (rest form)))))
171172

172173
(defn- dont-break?
@@ -302,7 +303,7 @@
302303
(vary-meta f1 assoc :cider/instrumented (name (:name (meta br))))
303304
f1))
304305
(m/strip-meta f keys))]
305-
;; also strip meta of the meta
306+
;; also strip meta of the meta
306307
(with-meta f (strip-instrumentation-meta (meta f))))
307308
f))
308309
form))

test/clj/cider/nrepl/middleware/debug_integration_test.clj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,29 @@
155155
(<-- {:value "2"}) ; (let ...)
156156
(<-- {:status ["done"]})))
157157

158+
(deftest debug-recur-test
159+
(--> :eval "(ns user.test.debug)")
160+
(<-- {:ns "user.test.debug"})
161+
(<-- {:status ["done"]})
162+
163+
(--> :eval
164+
"#dbg
165+
(defn foo [a]
166+
(if (pos? a)
167+
(recur (dec a))
168+
:done))")
169+
(<-- {:value "#'user.test.debug/foo"})
170+
(<-- {:status ["done"]})
171+
172+
(testing "recur on fn"
173+
(--> :eval "(foo 1)")
174+
(<-- {:debug-value "1" :coor [3 1 1]}) ; a
175+
(--> :continue)
176+
(<-- {:debug-value "0" :coor [3 1 1]}) ; a
177+
(--> :continue)
178+
(<-- {:value ":done"})
179+
(<-- {:status ["done"]})))
180+
158181
(deftest debug-ops-test
159182
(--> :eval "(ns user.test.debug)")
160183
(<-- {:ns "user.test.debug"})

test/clj/cider/nrepl/middleware/util/instrument_test.clj

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns cider.nrepl.middleware.util.instrument-test
1+
(ns ^:debugger cider.nrepl.middleware.util.instrument-test
22
(:require
33
[cider.nrepl.middleware.util.instrument :as t]
44
[clojure.set :as set]
@@ -70,11 +70,13 @@
7070
(if (seq x)
7171
(recur (rest x))
7272
x)))
73-
'#{[(rest (bp x {:coor [2 2 1 1]} x)) [2 2 1]]
74-
[x [2 2 1 1]]
75-
[x [2 1 1]]
76-
[x [2 3]]
77-
[(seq (bp x {:coor [2 1 1]} x)) [2 1]]})))
73+
'#{[x [2 2 1 1]]
74+
[(fn* ([x] (if (bp (seq (bp x {:coor [2 1 1]} x)) {:coor [2 1]} (seq x))
75+
(recur (bp (rest (bp x {:coor [2 2 1 1]} x)) {:coor [2 2 1]} (rest x)))
76+
(bp x {:coor [2 3]} x))))
77+
[]]
78+
[x [2 3]] [(seq (bp x {:coor [2 1 1]} x)) [2 1]] [x [2 1 1]]
79+
[(rest (bp x {:coor [2 2 1 1]} x)) [2 2 1]]})))
7880

7981
;; Factor this into a separate variable, otherwise Eastwood fails with
8082
;; "method code too large".

0 commit comments

Comments
 (0)