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

0 votes
in Spec by

While playing around with spec2, I'm seeing the following behavior which seems like a bug:

(s/def ::s1 (s/schema {:a string?}))
=> :dev.fp.livingdocs.specs/s1
(s/def ::s2 (s/schema {:b string?}))
=> :dev.fp.livingdocs.specs/s2
(s/def ::s3 (s/schema {:c string?}))
=> :dev.fp.livingdocs.specs/s3

;; The following is unexpected (neseted unions)
(s/def ::u (s/union ::s1 (s/union ::s2 ::s3)))
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1665$fn$G     (protocols.clj:20).
No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.lang.PersistentList
(s/def ::u (s/union (s/union ::s1 ::s2) ::s3))
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1665$fn$G (protocols.clj:20).
No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.lang.PersistentList

;; if I try to pull out the nested union into a separate keyword, it starts working 
(s/def ::u' (s/union ::s1 ::s2))
=> :dev.fp.livingdocs.specs/u'
(s/def ::u (s/union ::u' ::s3))
=> :dev.fp.livingdocs.specs/u
(s/explain (s/select ::u [:a :c]) {:a "bdfd"})
{:a "bdfd"} - failed: (fn [m] (contains? m :c))

;; but also this
(s/form ::ld/typed)
=>
(clojure.alpha.spec/schema
 [{:name clojure.core/string?, :type clojure.core/string?}])
(s/form ::ldd/editable)
=>
(clojure.alpha.spec/schema
 [{:optional clojure.core/boolean?,
   :maxLength clojure.core/integer?,
   :plainText clojure.core/boolean?,
   :excluexcludeFromTextCount clojure.core/boolean?}])
 
(s/def ::service
  (s/or :single (s/select (s/union ::ld/typed ::ldd/editable) [:type :name :optional])
         :multiple (s/select (s/union :ld/typed ::ldd/editable) [:type :name :maxLength])))
Execution error (IllegalArgumentException) at clojure.alpha.spec.protocols/eval1665$fn$G (protocols.clj:20).
No implementation of method: :keyspecs* of protocol: #'clojure.alpha.spec.protocols/Schema found for class: clojure.lang.PersistentList

In both cases s/union shows up in a nested position inside a form passed to a spec macro.

1 Answer

0 votes
by
selected by
 
Best answer

Thanks, I believe we already have a ticket for this. Spec 2 is a work in progress and not everything is working properly yet.

by
BTW, do you take patches (and if yes, how?) on this topic? I might have spotted the problem...
by
Yes, you can find the process here: https://clojure.org/dev/dev#_becoming_a_contributor
by
edited by
Thanks! I submitted https://clojure.atlassian.net/browse/CLJ-2613 as fix to this issue.

I also submitted https://clojure.atlassian.net/browse/CLJ-2612 witch fixes another issue in the same fn.
by
Thanks, both applied
...