diff --git a/src/malli/core.cljc b/src/malli/core.cljc index fead6e24b..660bc8490 100644 --- a/src/malli/core.cljc +++ b/src/malli/core.cljc @@ -2568,10 +2568,12 @@ (map? ?ast) (if-let [s (-lookup (:type ?ast) options)] (let [r (when-let [r (:registry ?ast)] (-delayed-registry r from-ast)) options (cond-> options r (-update :registry #(mr/composite-registry r (or % (-registry options))))) - ast (cond-> ?ast r (-update :properties #(assoc % :registry (-property-registry r options identity))))] - (cond (and (into-schema? s) (-ast? s)) (-from-ast s ast options) - (into-schema? s) (-into-schema s (:properties ast) (-vmap #(from-ast % options) (:children ast)) options) - :else s)) + ast (cond-> ?ast r (-update :properties #(assoc % :registry r)))] + (if (into-schema? s) + (if (-ast? s) + (-from-ast s ast options) + (-into-schema s (:properties ast) (-vmap #(from-ast % options) (:children ast)) options)) + s)) (-fail! ::invalid-ast {:ast ?ast})) :else (-fail! ::invalid-ast {:ast ?ast})))) diff --git a/test/malli/core_test.cljc b/test/malli/core_test.cljc index 617943971..cba1042ee 100644 --- a/test/malli/core_test.cljc +++ b/test/malli/core_test.cljc @@ -3581,3 +3581,27 @@ (is (not (m/validate [:sequential {:min 11} :int] (eduction identity (range 10))))) (is (not (m/validate [:seqable {:min 11} :int] (eduction identity (range 10))))) (is (nil? (m/explain [:sequential {:min 9} :int] (eduction identity (range 10)))))) + +(deftest from-ast-delayed-registry-test + (let [form [:int {:registry {::foo :int}}] + forced? (volatile! false) + original-delayed-registry m/-delayed-registry + ;;TODO refactor by providing custom IntoSchema constructor + s (with-redefs [m/-delayed-registry + (fn [m f] + (-> (original-delayed-registry m f) + (update-vals (fn [v] + (reify m/IntoSchema + (m/-into-schema [_ properties children options] + (vreset! forced? true) + (m/-into-schema v properties children options)))))))] + (m/from-ast (m/ast form))) + _ (is (not @forced?)) + form' (m/form s) + _ (is @forced?)] + (is (= form form')))) + +(comment + (m/from-ast (m/ast [:int {:registry {::foo :int}}])) + (m/form (m/from-ast (m/ast [:int {:registry {::foo :int}}]))) +)