Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

A node may not depend on itself #1

Closed
wants to merge 2 commits into from

2 participants

@tgoossens

Two reasons for my changes:

  • Its a directed graph that must not contains loops
  • depends? stackoverflows when a self-reference is existing
@stuartsierra
Owner

Fixed by commit 09c519b.

@noisesmith noisesmith referenced this pull request from a commit in noisesmith/dependency
@stuartsierra A node may not depend on itself
Also simplify generation of exception message. The *print-length*
binding was paranoid: nodes should probably not be large data
structures.

Originally reported by "tgoossens" here:
stuartsierra/dependency#1

Also added to tools.namespace:
clojure/tools.namespace@41cd3c3
09c519b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @tgoossens
  2. @tgoossens
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/com/stuartsierra/dependency.clj
View
12 src/com/stuartsierra/dependency.clj
@@ -40,16 +40,16 @@
(defn- remove-from-map [amap x]
(reduce (fn [m [k vs]]
- (assoc m k (disj vs x)))
- {} (dissoc amap x)))
+ (assoc m k (disj vs x)))
+ {} (dissoc amap x)))
(defn- transitive
"Recursively expands the set of dependency relationships starting
at (get m x)"
[m x]
(reduce (fn [s k]
- (set/union s (transitive m k)))
- (get m x) (get m x)))
+ (set/union s (transitive m k)))
+ (get m x) (get m x)))
(declare depends?)
@@ -71,6 +71,10 @@
(set (keys dependents))))
DependencyGraphUpdate
(depend [graph node dep]
+ (when (= node dep)
+ (let [^String msg (binding [*print-length* 10]
+ (str "The node " (pr-str node) " cannot depend on itself"))]
+ (throw (Exception. msg))))
(when (depends? graph dep node)
(let [^String msg (binding [*print-length* 10]
(str "Circular dependency between "
Something went wrong with that request. Please try again.