在specs alpha 2中,如果我们定义一个作为嵌套spec(其本身也是schema)的s/schema并且使用未命名空间键,然后尝试用s/valid?或s/exercise使用它,我们会遇到异常
s/valid
抛出“没有找到类:clojure.lang.Keyword实现的协议:'clojure.alpha.spec.protocols/Spec的方法”错误,而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}})