spec-alpha2 error with s/schema

66 views
Skip to first unread message

AJ Gardner

unread,
Jan 2, 2020, 12:24:34 PM1/2/20
to Clojure
Hello:

I ran into an issue where I can't conform (or anything else) to a schema which contains "aliased" specs:

(ns foo)
=> nil
(require '[clojure.alpha.spec :as s]
 '
[clojure.alpha.spec.gen :as gen])
=> nil
(s/def ::id int?)
=> :foo/id
(s/def ::tag-id ::id)
=> :foo/tag-id
(s/def ::child-tag ::tag-id)
=> :foo/child-tag
(s/conform ::child-tag 22)
=> 22
(s/conform ::child-tag "a")
=> :clojure.alpha.spec/invalid
(s/conform (s/schema [::child-tag]) {::child-tag 22})
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1458$fn$G (protocols.clj:11).
No implementation of method: :conform* of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword
(s/conform (s/schema [::tag-id]) {::tag-id 22})
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1458$fn$G (protocols.clj:11).
No implementation of method: :conform* of protocol: #'clojure.alpha.spec.protocols/Spec found for class: clojure.lang.Keyword
(s/conform (s/schema [::id]) {::id 22})
=> #:foo{:id 22}

Notice I have created a kind of spec alias chain.

I'm not sure what the problem is since I can conform values to the alias-of-alias specs, but once I use them in a schema, conformance doesn't work.

Thanks for taking a look.
Reply all
Reply to author
Forward
0 new messages