Skip to content

Commit 826c2e1

Browse files
plexusbbatsov
authored andcommitted
Fix problematic double var lookup in xref/fn-refs+fn-deps
`fn-deps` already calls `as-val` which will resolve a var if it is given one, so `fn-refs` does not need to call `(map var-get)` beforehand. Not doing this presents issues when a var contains a symbol. This currently would result in the symbol being treated as a var name, causing exceptions or incorrect results.
1 parent fa5bbb6 commit 826c2e1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

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

33
## master (unreleased)
44

5+
* [#135](https://github.com/clojure-emacs/orchard/issues/135): Fix problematic double var lookup in `orchard.xref/fn-refs`
6+
57
## 0.7.3 (2021-10-02)
68

79
### Changes

src/orchard/xref.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@
4848
[var]
4949
(let [var (as-var var)
5050
all-vars (q/vars {:ns-query {:project? true} :private? true})
51-
all-vals (map var-get all-vars)
52-
deps-map (zipmap all-vars (map fn-deps all-vals))]
51+
deps-map (zipmap all-vars (map fn-deps all-vars))]
5352
(map first (filter (fn [[_k v]] (contains? v var)) deps-map))))

test/orchard/xref_test.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
#{#'clojure.core/map #'clojure.core/filter
2121
#'clojure.core/even? #'clojure.core/range}))))
2222

23+
;; The mere presence of this var can reproduce a certain issue. See:
24+
;; https://github.com/clojure-emacs/orchard/issues/135#issuecomment-939731698
25+
(def xxx 'foo/bar)
26+
27+
;; Like the above, but programmatic, to ensure that we the presence of a .clj file named `foo`
28+
;; won't cause a false negative:
29+
(def yyy (symbol (str (gensym))
30+
(str (gensym))))
31+
2332
(deftest fn-refs-test
2433
(testing "with a fn value"
2534
(is (= (xref/fn-refs dummy-fn) '()))

0 commit comments

Comments
 (0)