From 2ad873da11c426325dc89881a8df5bcb33561fe0 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Mon, 11 Jan 2016 10:25:03 -0500 Subject: [PATCH] fixed #48 --- CHANGES.md | 1 + src/clj/com/rpl/specter/impl.cljx | 5 +++-- src/clj/com/rpl/specter/macros.clj | 11 +++++------ test/com/rpl/specter/core_test.cljx | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ad204cc..3622b26 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,7 @@ ## 0.9.2 (unreleased) * Added VOID selector which navigates nowhere * Better syntax checking for defpath +* Fixed bug in protocol paths (#48) ## 0.9.1 * Fixed reflection in protocol path code diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 84b592f..319cf69 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -597,6 +597,7 @@ m (-> protpath-prot :sigs keys first)] (doseq [[atype apath] extensions] ;;TODO: validate that the path has the correct number of args (or none at all) - (let [p (comp-paths* apath)] - (extend atype protpath-prot {m (fn [_] p)}) + (let [p (comp-paths* apath) + rp (assoc p :transform-fns (coerce-tfns-rich (:transform-fns p)))] + (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 cdece6a..4fcc384 100644 --- a/src/clj/com/rpl/specter/macros.clj +++ b/src/clj/com/rpl/specter/macros.clj @@ -210,7 +210,6 @@ m (-> name (str "-retrieve") symbol) num-params (count params) ssym (gensym "structure") - sargs [ssym (gensym "next-fn")] rargs [(gensym "params") (gensym "pidx") (gensym "vals") ssym (gensym "next-fn")] retrieve `(~m ~ssym) ] @@ -220,16 +219,16 @@ (if (= ~num-params 0) (no-params-compiled-path (->TransformFunctions - StructurePathExecutor - (fn ~sargs + RichPathExecutor + (fn ~rargs (let [path# ~retrieve selector# (compiled-selector path#)] - (selector# ~@sargs) + (selector# ~@rargs) )) - (fn ~sargs + (fn ~rargs (let [path# ~retrieve transformer# (compiled-transformer path#)] - (transformer# ~@sargs) + (transformer# ~@rargs) )))) (->ParamsNeededPath (->TransformFunctions diff --git a/test/com/rpl/specter/core_test.cljx b/test/com/rpl/specter/core_test.cljx index cd5848d..e8b31cf 100644 --- a/test/com/rpl/specter/core_test.cljx +++ b/test/com/rpl/specter/core_test.cljx @@ -639,3 +639,24 @@ inc data))) )) + + +#+clj +(do + (defprotocolpath CustomWalker []) + (extend-protocolpath CustomWalker + Object nil + clojure.lang.PersistentHashMap [(s/keypath :a) CustomWalker] + clojure.lang.PersistentArrayMap [(s/keypath :a) CustomWalker] + clojure.lang.PersistentVector [s/ALL CustomWalker] + ) + + ) + +#+clj +(deftest mixed-rich-regular-protocolpath + (is (= [1 2 3 11 21 22 25] + (s/select [CustomWalker number?] [{:a [1 2 :c [3]]} [[[[[[11]]] 21 [22 :c 25]]]]]))) + (is (= [2 3 [[[4]] :b 0] {:a 4 :b 10}] + (s/transform [CustomWalker number?] inc [1 2 [[[3]] :b -1] {:a 3 :b 10}]))) + )