嗨,我正在这里报告我认为是一周内的第二个与规范工具相关的怪异现象。
如果这已经作为 bug 报告过,我表示歉意;但基本上,我不明白为什么最后一个调用会引发错误 -::id-map
规范根本不需要检查 ::other
。
(ns repro-spec.test
(:require [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st]))
(s/def ::impl any?)
(s/def ::id string?)
(s/def ::other number?)
(s/def ::id-map (s/keys :req [::id]))
(s/fdef delete-impl
:args (s/cat :impl ::impl
:id-map ::id-map))
(defn delete-impl [_ id-map]
(println (str "This deletes " (::id id-map)))
id-map)
(st/instrument)
(delete-impl {} {::id "test"})
;; prints "This deletes test"
(delete-impl {} {::id "test" ::other "ignore me"})
;; Execution error - invalid arguments to repro-spec.test/delete-impl at (REPL:27).
;; "ignore me" - failed: number? at: [:id-map :repro-spec.test/other] spec: :repro-spec.test/other
是我做错了什么吗?