metosin/malli

mx/defn and malli.destructure/parse unexpected handling of seqexps

開放

#1,005 建立於 2024年2月1日

 (4 則留言) (0 個反應) (0 位負責人)Clojure (237 個分叉)batch import
documentationhelp wanted

倉庫指標

星標
 (1,724 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

If I write

(require '[malli.experimental :as mx])
(require '[malli.core :as m])

(mx/defn ^:malli/always f [xs :- [:* :int]]
  (malli.core/validate [:* :int] xs))

(f 1)
;; => false

(f [1])
;; => Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:136).
;;    :malli.core/invalid-input

(m/validate [:* :int] [1])
;; => true

I would expect (f 1) to throw an except and (f [1]) to return true.

I think this is because the schemas for the arguments are combined using [:cat ...] and [:cat [:* :int]] 'flattens' the expression, so [[1]] is not valid for [:cat [:* :int]]. In this simple case the args schema should be something like [:tuple [:* :int]] for which [[1]] is valid.

Of course this is not so simple for varargs.

貢獻者指南