metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.43k stars 204 forks source link

`:?` doesn't work properly in function schemas in cljs #1063

Open simonacca opened 1 month ago

simonacca commented 1 month ago

Hi there, I encountered a discrepancy in the behavior of multi-arity schemas in clj vs cljs, seems like a bug.

In the following example, the spec is defined with the documented syntax for multi-arity functions. This fails both in clj and cljs, as expected, so far so good.

(defn myfn-a
  {:malli/schema [:function 
                  [:=> [:cat :int :int ] :keyword]
                  [:=> [:cat :int :int :string] :keyword]]}
  ([a b] :res1)
  ([a b c] :res2))

(myfn-a 1 2 3)

The following spec however fails with "invalid function arguments" in clj (expected behavior) and succeeds silently (that is, it doesn't throw any error) in cljs (this is surprising to me).

(defn myfn-b
  {:malli/schema [:=> [:cat :int [:? :int] :string] :keyword]}
  ([a b] :res3)
  ([a b c] :res4))
(myfn-b 1 2 3)