summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj26
-rw-r--r--src/script/run_tests.clj1
2 files changed, 19 insertions, 8 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 6fa139dd..16186d47 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -5071,8 +5071,8 @@
(defonce ^:dynamic
^{:private true
- :doc "the set of paths currently being loaded by this thread"}
- *pending-paths* #{})
+ :doc "A stack of paths currently being loaded by this thread"}
+ *pending-paths* ())
(defonce ^:dynamic
^{:private true :doc
@@ -5206,8 +5206,20 @@
(doseq [arg args]
(apply load-lib prefix (prependss arg opts))))))))
-;; Public
+(defn- check-cyclic-dependency
+ "Detects and rejects non-trivial cyclic load dependencies. The
+ exception message shows the dependency chain with the cycle
+ highlighted. Ignores the trivial case of a file attempting to load
+ itself because that can occur when a gen-class'd class loads its
+ implementation."
+ [path]
+ (when (some #{path} (rest *pending-paths*))
+ (let [pending (map #(if (= % path) (str "[ " % " ]") %)
+ (cons path *pending-paths*))
+ chain (apply str (interpose "->" pending))]
+ (throw (Exception. (str "Cyclic load dependency: " chain))))))
+;; Public
(defn require
"Loads libs, skipping any that are already loaded. Each argument is
@@ -5300,12 +5312,10 @@
(when *loading-verbosely*
(printf "(clojure.core/load \"%s\")\n" path)
(flush))
-; (throw-if (*pending-paths* path)
-; "cannot load '%s' again while it is loading"
-; path)
- (when-not (*pending-paths* path)
+ (check-cyclic-dependency path)
+ (when-not (= path (first *pending-paths*))
(binding [*pending-paths* (conj *pending-paths* path)]
- (clojure.lang.RT/load (.substring path 1)))))))
+ (clojure.lang.RT/load (.substring path 1)))))))
(defn compile
"Compiles the namespace named by the symbol lib into a set of
diff --git a/src/script/run_tests.clj b/src/script/run_tests.clj
index 5b4ba07e..ef29cd43 100644
--- a/src/script/run_tests.clj
+++ b/src/script/run_tests.clj
@@ -23,6 +23,7 @@ clojure.test-clojure.java.javadoc
clojure.test-clojure.java.shell
clojure.test-clojure.java-interop
clojure.test-clojure.keywords
+clojure.test-clojure.load
clojure.test-clojure.logic
clojure.test-clojure.macros
clojure.test-clojure.main