diff options
author | Rich Hickey <richhickey@gmail.com> | 2010-04-16 13:23:15 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2010-04-16 13:23:15 -0400 |
commit | f47895ad8a4a8eac74ccc43c60645c9b121e7d0c (patch) | |
tree | 04eb4365f3d0d313a32abff909bd5319f774981b | |
parent | 728c4c910595332dffd4308ed24364356d330471 (diff) |
check that type does not already implement protocol interface when extending, fixes #294
-rw-r--r-- | src/clj/clojure/core_deftype.clj | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj index 40d21c7d..4dc27d3a 100644 --- a/src/clj/clojure/core_deftype.clj +++ b/src/clj/clojure/core_deftype.clj @@ -387,10 +387,13 @@ (defn find-protocol-method [protocol methodk x] (get (find-protocol-impl protocol x) methodk)) +(defn- implements? [protocol atype] + (.isAssignableFrom #^Class (:on-interface protocol) atype)) + (defn extends? "Returns true if atype extends protocol" [protocol atype] - (boolean (or (.isAssignableFrom #^Class (:on-interface protocol) atype) + (boolean (or (implements? protocol atype) (get (:impls protocol) atype)))) (defn extenders @@ -598,6 +601,10 @@ [atype & proto+mmaps] (doseq [[proto mmap] (partition 2 proto+mmaps)] + (when (implements? proto atype) + (throw (IllegalArgumentException. + (str atype " already directly implements " (:on-interface proto) " for protocol:" + (:var proto))))) (-reset-methods (alter-var-root (:var proto) assoc-in [:impls atype] mmap)))) (defn- emit-impl [[p fs]] |