在 specs alpha 2 中,如果我们定义一个 clojure.alpha.spec/select
的 spec,该 spec 是一个嵌套 spec,它本身也是 s/schema
,但键是不带命名空间的,并尝试使用 s/valid?
或 s/exercise
,我们会得到异常
s/valid
抛出 *"未找到类 clojure.lang.Keyword 方法: :conform 的实现,属于协议: #'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}})