From e37c605697686c8863e0893f7fc54a521153bf4d Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Mon, 11 Jan 2016 14:45:06 -0500 Subject: [PATCH] protocol path extensions now verify if correct number of parameters and error otherwise --- src/clj/com/rpl/specter/impl.cljx | 14 ++++++++++---- src/clj/com/rpl/specter/macros.clj | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 319cf69..e4d5725 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -591,13 +591,19 @@ (let [^com.rpl.specter.impl.TransformFunctions tfns (.-transform-fns path)] (.-transformer tfns))) + + #+clj -(defn extend-protocolpath* [protpath-prot extensions] +(defn extend-protocolpath* [protpath protpath-prot extensions] (let [extensions (partition 2 extensions) - m (-> protpath-prot :sigs keys first)] + m (-> protpath-prot :sigs keys first) + expected-params (num-needed-params protpath)] (doseq [[atype apath] extensions] - ;;TODO: validate that the path has the correct number of args (or none at all) (let [p (comp-paths* apath) - rp (assoc p :transform-fns (coerce-tfns-rich (:transform-fns p)))] + rp (assoc p :transform-fns (coerce-tfns-rich (:transform-fns p))) + needed-params (num-needed-params rp)] + (if-not (= needed-params expected-params) + (throw-illegal "Invalid number of params in extended protocol path, expected " + expected-params " but got " needed-params)) (extend atype protpath-prot {m (fn [_] rp)}) )))) diff --git a/src/clj/com/rpl/specter/macros.clj b/src/clj/com/rpl/specter/macros.clj index 4fcc384..c442267 100644 --- a/src/clj/com/rpl/specter/macros.clj +++ b/src/clj/com/rpl/specter/macros.clj @@ -248,4 +248,4 @@ ))))) (defmacro extend-protocolpath [protpath & extensions] - `(extend-protocolpath* ~(protpath-sym protpath) ~(vec extensions))) + `(extend-protocolpath* ~protpath ~(protpath-sym protpath) ~(vec extensions)))