Skip to content

Commit 3824d72

Browse files
authored
Fix the debugger in case of a local shadows a var (#847)
Fixes #846
1 parent ca4a5fe commit 3824d72

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
## Bugs fixed
6+
7+
* [#846](https://github.com/clojure-emacs/cider-nrepl/issues/846): `middleware.debug`: use `resolve` with `&env` to fix debugging in case of a local shadows a var.
8+
59
## 0.45.0 (2024-01-14)
610

711
### Changes

src/cider/nrepl/middleware/debug.clj

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -447,17 +447,21 @@ this map (identified by a key), and will `dissoc` it afterwards."}
447447

448448
(defn looks-step-innable?
449449
"Decide whether a form looks like a call to a function that we could
450-
instrument and step into."
451-
[form]
452-
(when (and (seq? form) (symbol? (first form)))
453-
(let [v (resolve (first form)) ; Note: special forms resolve to nil
454-
m (meta v)]
455-
;; We do not go so far as to actually try to read the code of the function
456-
;; at this point, which is at macroexpansion time.
457-
(and v
458-
(safe-to-debug? (:ns m))
459-
(not (:macro m))
460-
(not (:inline m))))))
450+
instrument and step into.
451+
You should prefer the second arity with the `&env` argument
452+
to handle a local shadowing correctly."
453+
([form]
454+
(looks-step-innable? nil form))
455+
([&env form]
456+
(when (and (seq? form) (symbol? (first form)))
457+
(let [v (resolve &env (first form)) ; Note: special forms resolve to nil
458+
m (meta v)]
459+
;; We do not go so far as to actually try to read the code of the function
460+
;; at this point, which is at macroexpansion time.
461+
(and v
462+
(safe-to-debug? (:ns m))
463+
(not (:macro m))
464+
(not (:inline m)))))))
461465

462466
;;; ## Breakpoint logic
463467

@@ -547,7 +551,7 @@ this map (identified by a key), and will `dissoc` it afterwards."}
547551
(defmacro expand-break
548552
"Internal macro to avoid code repetition in `breakpoint-if-interesting`."
549553
[form {:keys [coor]} original-form]
550-
(let [val-form (if (looks-step-innable? form)
554+
(let [val-form (if (looks-step-innable? &env form)
551555
(let [[fn-sym & args] form]
552556
`(apply-instrumented-maybe (var ~fn-sym) [~@args] ~coor ~'STATE__))
553557
form)
@@ -570,9 +574,8 @@ this map (identified by a key), and will `dissoc` it afterwards."}
570574
`irrelevant-return-value-forms`."
571575
[&env form]
572576
(or (and (symbol? form)
573-
(not (contains? &env form))
574577
(try
575-
(-> (resolve form) meta :ns
578+
(-> (resolve &env form) meta :ns
576579
ns-name #{'clojure.core 'schema.core})
577580
(catch Exception _ nil)))
578581
(and (seq? form)

0 commit comments

Comments
 (0)