It also seems to come up with coll-of + or: user> (s/def ::a (s/or :even even? :odd odd?)) user> (s/def ::c (s/coll-of ::a)) user> (s/conform ::c [1 2 3 4]) [[:odd 1] [:even 2] [:odd 3] [:even 4]] user> (s/unform ::c (s/conform ::c [1 2 3 4])) [[:odd 1] [:even 2] [:odd 3] [:even 4]]
It looks like coll-of calls every-impl which just has identity as it's unform fn. -Jenny On Wednesday, May 31, 2017 at 9:37:43 PM UTC-7, Jenny Finkel wrote: > > I think I found a bug in spec when combining merge and or. Basically, when > you conform a map where one of the keys has an or, and the spec comes from > a clojure.spec/merge, one of the underlying keys will conform it, while the > others don't, and then when the results get merged together you can end up > with the unconformed version in the result: > > user> (require '[clojure.spec :as s]) > user> (s/def ::a (s/or :even even? :odd odd?)) > user> (s/def ::b (s/or :even even? :odd odd?)) > user> (s/def ::m1 (s/keys :req-un [::a])) > user> (s/def ::m2 (s/keys :req-un [::b])) > user> (s/def ::mm (s/merge ::m1 ::m2)) > user> (s/valid? ::mm {:a 1 :b 2}) > true > user> (s/conform ::mm {:a 1 :b 2}) > {:a 1, :b [:even 2]} > user> (s/unform ::mm {:a [:odd 1] :b [:even 2]}) > {:a 1, :b [:even 2]} > user> (s/unform ::mm (s/conform ::mm {:a 1 :b 2})) > UnsupportedOperationException nth not supported on this type: Long > clojure.lang.RT.nthFrom (RT.java:962) > > I guess that valid? checks if it satisfies all the merged specs, and > conform conforms on each and merges, and then unform can end up with a > result that it can't unform (and similarly, if you give unform a properly > conformed thing it can't unform properly due to how it merges results as > well). I think the fix would be an update to clojure.spec/merge to make it > smarter about which keys to keep from each map on conforming and unforming, > though looking at the current code I don't think it's an easy fix. > > -Jenny > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.