From c4f26ebce4da8961a7fbada335900083fcb39c87 Mon Sep 17 00:00:00 2001 From: Arne Brasseur Date: Mon, 11 Oct 2021 08:50:11 +0200 Subject: [PATCH] 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. --- CHANGELOG.md | 2 ++ src/orchard/xref.clj | 3 +-- test/orchard/xref_test.clj | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5382270..bd18070a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master (unreleased) +* [#135](https://github.com/clojure-emacs/orchard/issues/135): Fix problematic double var lookup in `orchard.xref/fn-refs` + ## 0.7.3 (2021-10-02) ### Changes diff --git a/src/orchard/xref.clj b/src/orchard/xref.clj index c7e6bb05..c11dfb90 100644 --- a/src/orchard/xref.clj +++ b/src/orchard/xref.clj @@ -48,6 +48,5 @@ [var] (let [var (as-var var) all-vars (q/vars {:ns-query {:project? true} :private? true}) - all-vals (map var-get all-vars) - deps-map (zipmap all-vars (map fn-deps all-vals))] + deps-map (zipmap all-vars (map fn-deps all-vars))] (map first (filter (fn [[_k v]] (contains? v var)) deps-map)))) diff --git a/test/orchard/xref_test.clj b/test/orchard/xref_test.clj index 0dd743cc..a7c1c46d 100644 --- a/test/orchard/xref_test.clj +++ b/test/orchard/xref_test.clj @@ -20,6 +20,15 @@ #{#'clojure.core/map #'clojure.core/filter #'clojure.core/even? #'clojure.core/range})))) +;; The mere presence of this var can reproduce a certain issue. See: +;; https://github.com/clojure-emacs/orchard/issues/135#issuecomment-939731698 +(def xxx 'foo/bar) + +;; Like the above, but programmatic, to ensure that we the presence of a .clj file named `foo` +;; won't cause a false negative: +(def yyy (symbol (str (gensym)) + (str (gensym)))) + (deftest fn-refs-test (testing "with a fn value" (is (= (xref/fn-refs dummy-fn) '()))