Welcome! Please see the About page for a little more info on how this works.

+2 votes
in Libs by
retagged by

In specs alpha 2, if we define a clojure.alpha.spec/select of a spec defined as a s/schema of a nested spec that is itself a s/schema, but of unnamespaced keys, and try to use it with either s/valid? or s/exercise, we get exceptions:
s/valid throws *"No implementation of method: :conform of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword" and s/exercise throws "Unable to resolve spec: :foo"** (where :foo is the unnamespaced key).

An example can illustrate the issue better:

; 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}})

2 Answers

+1 vote
by

My first reaction is "Spec 2 is not ready for use yet and has a number of bugs" as Alex has said in response to most questions about it.

I would have expected the syntax for ::inner to be:
(s/def ::inner (s/schema {:foo ::foo}))
based on the wiki documentation, but that doesn't work either (so I come back to "It's one of many bugs in Spec 2 right now").

by
Can confirm this issue is still present in Spec2 alpha as of 2020-08-24 (latest commit to master: d514b06b25c41a676b95afcc9bfac8ca34c5741e).
by
My workaround is to use s/keys until schemas are stable.
0 votes
by
...