summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2009-11-12 14:00:53 -0500
committerRich Hickey <richhickey@gmail.com>2009-11-12 14:00:53 -0500
commitbebb1ff5cb80b863a3aba2ba21eaafc843f990da (patch)
treecb55a1f5dc4ac375bc9610a042645b7ddf56a9f8
parent292836f87260fdb994d25a98ef65b4edebf9d09e (diff)
use hierarchy to determine impl given multiple extends in superclasses of target, now: target type, target class, superclasses (not interfaces) of target (in reverse derivation order, not including Object), interfaces (in arbitrary order for now), Object
-rw-r--r--src/clj/clojure/core_deftype.clj9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj
index 09d59cb7..c2f71d40 100644
--- a/src/clj/clojure/core_deftype.clj
+++ b/src/clj/clojure/core_deftype.clj
@@ -201,6 +201,10 @@
table cs)]
(clojure.lang.MethodImplCache. (.protocol cache) (.methodk cache) shift mask table)))
+(defn- super-chain [#^Class c]
+ (when c
+ (cons c (super-chain (.getSuperclass c)))))
+
(defn find-protocol-impl [protocol x]
(if (and (:on protocol) (instance? (:on protocol) x))
x
@@ -209,8 +213,9 @@
impl #(get (:impls protocol) %)]
(or (impl t)
(impl c)
- ;todo - better path, how to prioritize supers vs interfaces?
- (first (remove nil? (map impl (supers c))))))))
+ (first (remove nil? (map impl (butlast (super-chain c)))))
+ (first (remove nil? (map impl (disj (supers c) Object))))
+ (impl Object)))))
(defn find-protocol-method [protocol methodk x]
(get (find-protocol-impl protocol x) methodk))