diff --git a/src/malli/clj_kondo.cljc b/src/malli/clj_kondo.cljc index 83694d3ed..4b3e90935 100644 --- a/src/malli/clj_kondo.cljc +++ b/src/malli/clj_kondo.cljc @@ -103,7 +103,7 @@ (defmethod accept :tuple [_ _ _ _] :seqable) (defmethod accept :multi [_ _ _ _] :any) ;;?? (defmethod accept :re [_ _ _ _] :string) -(defmethod accept :fn [_ _ _ _] :fn) +(defmethod accept :fn [_ _ _ _] :any) (defmethod accept :ref [_ _ _ _] :any) ;;?? (defmethod accept :=> [_ _ _ _] :fn) (defmethod accept :function [_ _ _ _] :fn) diff --git a/test/malli/clj_kondo_test.cljc b/test/malli/clj_kondo_test.cljc index 147fec527..8c0630456 100644 --- a/test/malli/clj_kondo_test.cljc +++ b/test/malli/clj_kondo_test.cljc @@ -59,8 +59,21 @@ [:=> [:cat :int :int] :nil] [:=> [:cat :int :int [:repeat :int]] :nil]]) -(deftest clj-kondo-integration-test +(defn clj-kondo-issue-836-1 + "Predicate `:fn` schema's should be type-checked as expecting to be passed `:any`, not a fn." + [x y z] (* x y z)) +(m/=> clj-kondo-issue-836-1 [:=> [:cat int? [:fn #(int? %)] int?] [:fn #(int? %)]]) + +(defn- cljk-collect-for-test + "Collect up all of the clj-kondo linters generated for fn's in this test ns." + [] + (-> 'malli.clj-kondo-test + #?(:clj (clj-kondo/collect)) + #?(:cljs (clj-kondo/collect-cljs)) + (clj-kondo/linter-config) + (get-in [:linters :type-mismatch :namespaces]))) +(deftest clj-kondo-integration-test (is (= {:op :keys, :opt {::price :double, :tags :set, ::y :boolean}, :req {::id :string, @@ -109,21 +122,14 @@ :ret :nil} :varargs {:args [:int :int {:op :rest :spec :int}] :ret :nil - :min-arity 2}}}}}] - + :min-arity 2}}} + ;; should output `:any` for `:fn` predicate schema's, not `:fn` + 'clj-kondo-issue-836-1 + {:arities {3 {:args [:int :any :int], :ret :any}}}}}] #?(:clj - (is (= expected-out - (-> 'malli.clj-kondo-test - (clj-kondo/collect) - (clj-kondo/linter-config) - (get-in [:linters :type-mismatch :namespaces]))))) - + (is (= expected-out (cljk-collect-for-test)))) #?(:cljs - (is (= expected-out - (-> 'malli.clj-kondo-test - (clj-kondo/collect-cljs) - (clj-kondo/linter-config) - (get-in [:linters :type-mismatch :namespaces])))))) + (is (= expected-out (cljk-collect-for-test))))) (testing "sequential elements" (is (= :seqable (clj-kondo/transform [:repeat :int]))) diff --git a/test/malli/instrument_test.clj b/test/malli/instrument_test.clj index 85df57d37..e440ca416 100644 --- a/test/malli/instrument_test.clj +++ b/test/malli/instrument_test.clj @@ -90,6 +90,11 @@ (mi/-schema #'f2))) (is (= nil (mi/-schema #'f3)))) +(deftest check-test + (testing "all registered function schemas in this namespace" + (let [results (mi/check {:filters [(mi/-filter-ns 'malli.instrument-test)]})] + (is (map? results))))) + (deftest instrument-external-test (testing "Without instrumentation" diff --git a/test/malli/instrument_test.cljs b/test/malli/instrument_test.cljs index fbe6b30b1..94a792c87 100644 --- a/test/malli/instrument_test.cljs +++ b/test/malli/instrument_test.cljs @@ -194,8 +194,9 @@ (is (= 9 (minus-small-int 10))))) (deftest ^:simple check-test - (let [results (mi/check)] - (is (map? results)))) + (testing "all registered function schemas in this namespace" + (let [results (mi/check {:filters [(mi/-filter-ns 'malli.instrument-test)]})] + (is (map? results))))) (deftest ^:simple instrument-external-test