Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rfhayashi opened this issue Oct 28, 2021 · 1 comment
Open

Comments

@rfhayashi
Copy link

(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
Copy link
Contributor

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!

arichiardi added a commit to cohesic/spec-tools that referenced this issue Mar 19, 2024
Trying to workaround the following issue, waiting for an actual fix:
  metosin#262

This path prevents throwing the error:

  java.lang.UnsupportedOperationException: nth not supported on this type: PersistentArrayMap
	at clojure.lang.RT.nthFrom(RT.java:992)
	at clojure.lang.RT.nth(RT.java:940)
	at clojure.spec.alpha$or_spec_impl$reify__2112.unform_STAR_(alpha.clj:1101)
	at clojure.spec.alpha$unform.invokeStatic(alpha.clj:178)
	at clojure.spec.alpha$unform.invoke(alpha.clj:173)
	at clojure.spec.alpha$merge_spec_impl$reify__2190$fn__2193.invoke(alpha.clj:1210)
	at clojure.core$map$fn__5935.invoke(core.clj:2772)
	at clojure.lang.LazySeq.sval(LazySeq.java:42)
	at clojure.lang.LazySeq.seq(LazySeq.java:51)
	at clojure.lang.RT.seq(RT.java:535)
	at clojure.core$seq__5467.invokeStatic(core.clj:139)
	at clojure.core$apply.invokeStatic(core.clj:662)
	at clojure.core$apply.invoke(core.clj:662)
	at clojure.spec.alpha$merge_spec_impl$reify__2190.unform_STAR_(alpha.clj:1210)
	at clojure.spec.alpha$unform.invokeStatic(alpha.clj:178)
	at clojure.spec.alpha$unform.invoke(alpha.clj:173)
	at spec_tools.core.Spec.unform_STAR_(core.cljc:439)
    ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants