Skip to content

Commit

Permalink
TNS-38: ignore dependency on self, for CLJS
Browse files Browse the repository at this point in the history
In Clojure (.clj) code, a namespace depending on itself makes no sense.
But it is perfectly reasonable for a ClojureScript (.cljs) file to
depend on a Clojure (.clj) file for macro definitions in the same
namespace, via :require-macros.

More generally, this means that a "namespace" is logically defined in
multiple files, which tools.namespace does not yet handle.

This causes spurious circular-dependency error in tools. See, for
example, clojure-emacs/refactor-nrepl#127

It is easy to work around the specific case of self-dependency via
:require-macros, which has no meaning anywhere else.

As a consequence, tools.namespace will no longer throw an exception if
an ordinary Clojure namespace tries to :require itself.
  • Loading branch information
Stuart Sierra committed Nov 6, 2015
1 parent f9f11f4 commit 6b19f94
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/clojure/clojure/tools/namespace/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
(defn deps-from-ns-decl
"Given an (ns...) declaration form (unevaluated), returns a set of
symbols naming the dependencies of that namespace. Handles :use and
:require clauses but not :load."
:require clauses but not :load. Ignores a namespace depending on
itself, for example a .cljs file with :require-macros on the .clj
file of the same namespace."
[decl]
(set (mapcat deps-from-ns-form decl)))
(disj (set (mapcat deps-from-ns-form decl))
(name-from-ns-decl decl)))

0 comments on commit 6b19f94

Please sign in to comment.