在 specs alpha 2 中,如果我们定义一个作为嵌套 spec 的 s/schema 的 spec(它本身也是一个 s/schema,但其键未命名空间),然后尝试使用 s/valid? 或 s/exercise,我们会得到异常
s/valid
抛出 *"没有为类:clojure.lang.Keyword 的协议:'#clojure.alpha.spec.protocols/Spec' 找到方法::conform",而 s/exercise
抛出 "无法解析 spec::foo"**(其中 :foo
是未命名空间键)。
一个例子可以更好地说明问题
; Context
(s/def ::foo int?)
(s/def ::inner (s/schema [{:foo ::foo}]))
(s/def ::outer (s/schema [::inner]))
; Works as expected:
(s/exercise ::outer)
(s/exercise (s/select ::inner [*]))
(s/valid? (s/select ::inner [*]) {:foo 10})
; Fails with "Unable to resolve spec: :foo"
(s/exercise (s/select ::outer [*]))
; Fails with "No implementation of method: :conform* of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword"
(s/valid? (s/select ::outer [*]) {::inner {:foo 10}})