在spec alpha 2中,如果我们定义了一个适用于未命名空间键的嵌套spec的s/schema的s/select,然后尝试使用s/valid?或s/exercise来使用它,我们会遇到异常。
s/valid
抛出“没有实现::conform方法”的错误,协议:#'clojure.alpha.spec.protocols/Spec未在类:clojure.lang.Keyword中找到;而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}})