metosin / spec-tools

Clojure(Script) tools for clojure.spec
Eclipse Public License 2.0
593 stars 94 forks source link

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

Open rfhayashi opened 3 years ago

rfhayashi commented 3 years ago
(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.

arichiardi commented 8 months ago

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!