Hi Alex, I could track down why explain stops early. http://dev.clojure.org/jira/browse/CLJ-2013
On Wednesday, August 24, 2016 at 11:33:43 PM UTC+2, Leon Grapenthin wrote: > > > On Tuesday, August 23, 2016 at 3:27:28 AM UTC+2, Alex Miller wrote: >> >> predicate: (cat :args (* :clojure.core.specs/binding-form) :varargs (? >> (cat :amp #{(quote &)} :form :clojure.core.specs/binding-form))), >> >> the predicate that is actually failing in the spec, probably not >> particularly helpful given the complexity (and recursiveness) of the >> destructuring specs >> >> >> Extra input >> >> this is the part of cat that I think could be made more explicit - could >> be saying here that the value it had (above) was expected to match the next >> part of the cat (binding-form). So that could say the equivalent of >> "Expected binding-form but had non-matching value ..." and could even find >> what parts of that value matched and maybe which didn't (the :or keys) such >> that you'd have a more precise description. There is some more stuff Rich >> and I have worked on around "hybrid maps" which is the case here with map >> destructuring - it's particularly challenging to get a good error out of >> that at the moment, but there's more that can be done. >> >> > Thank you for doing the walkthrough. I observed this too and became > sceptical why spec doesn't go further down the path and apparently stops at > ::binding-form. > I could isolate the problem a bit by changing the spec of ::arg-list and > temporarily removing the :varargs branch. > > (s/def ::arg-list > (s/and > vector? > (s/cat :args (s/* ::binding-form) > ;; :varargs (s/? (s/cat :amp #{'&} :form ::binding-form)) > ))) > > This leads to a much better message: > > (s/explain (:args (s/get-spec 'clojure.core/defn)) > '[foo [{:or {a/b 42}}]]) > > In: [1 0] val: {:or #:a{b 42}} fails spec: :clojure.core.specs/local-name > at: [:bs :arity-1 :args :args :sym] predicate: simple-symbol? > In: [1 0 0] val: ([:or #:a{b 42}]) fails spec: > :clojure.core.specs/seq-binding-form at: [:bs :arity-1 :args :args :seq] > predicate: (cat :elems (* :clojure.core.specs/binding-form) :rest (? (cat > :amp #{(quote &)} :form :clojure.core.specs/binding-form)) :as (? (cat :as > #{:as} :sym :clojure.core.specs/local-name))), Extra input > In: [1 0 :or a/b 0] val: a/b fails spec: :clojure.core.specs/or at: [:bs > :arity-1 :args :args :map :or 0] predicate: simple-symbol? > In: [1 0] val: {:or #:a{b 42}} fails spec: :clojure.core.specs/arg-list > at: [:bs :arity-n :bodies :args] predicate: vector? > > The third one is the desired one and very precise - it seems to be usually > the one with the largest :in path. The length of the :in path seems a good > sorting criterium for reporting. > > However I was not able to track the issue further down. I also wasn't able > to reproduce a more minimal case of this problem. It seems like a bug in > how spec parses and must have something to do with s/cat and the :varargs > branch. > -- 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.