metosin / spec-tools

Clojure(Script) tools for clojure.spec

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

s/explain-data throws exception for s/map-of spec with a s/or key

rfhayashi opened this issue · comments

(s/explain-data
 (st/spec
  (s/map-of (s/or :keyword keyword? :string string?) any?))
 {:a 1})

throws a nth not supported on this type: Keyword exception.

This is due to a known issue of clojure spec (https://clojure.atlassian.net/browse/CLJ-2199).

Although we could wait for that fix, I think the call to s/unform here seems unnecessary since at that point we still have the original value. Doing this did solve the problem for me.

Is my understanding correct? Wanted to confirm before opening a PR.

Wanted to conf_o_rm (ah!) that the fix above from @rfhayashi works here as well against the following spec:

(s/def ::age nat-int?)

(def age-interval-bound
  (ds/or {:infinity (s/spec #{##Inf ##-Inf})
          :nat-int ::age}))
(def age-interval-bound-spec (ds/spec {:name ::age-interval-bound :spec age-interval-bound}))
(s/def ::age-interval-bound age-interval-bound-spec)

(def age-interval
  {:lower-bound age-interval-bound
   :upper-bound age-interval-bound
   (ds/opt :open-lower) boolean?
   (ds/opt :open-upper) boolean?})
(def age-interval-spec (ds/spec {:name ::age-interval :spec age-interval}))
(s/def ::age-interval age-interval-spec)

Looking forward to a patch (that I can definitely open if the fix is acceptable). Thanks!