Clojure

[spec] clojure.spec: :pred in explain for coll-of should have resolved symbols

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.9
  • Fix Version/s: Release 1.10
  • Component/s: None
  • Labels:
  • Environment:
    0.1.123
  • Patch:
    Code and Test
  • Approval:
    Vetted

Description

:pred should be resolved in explain problems like:

s/coll-of and s/every-kv should have resolved :pred functions if it's values aren't valid:

(::s/problems (s/explain-data (s/coll-of (fn [x] (pos? x))) [-1]))
({:path [], :pred (fn [x] (pos? x)), :val -1, :via [], :in [0]})

should be

(::s/problems (s/explain-data (s/coll-of (fn [x] (pos? x))) [-1]))
({:path [], :pred (clojure.core/fn [x] (clojure.core/pos? x)), :val -1, :via [], :in [0]})

Other examples:

;; same with every
(::s/problems (s/explain-data (s/every (fn [x] (pos? x))) [-1]))
({:path [], :pred (fn [x] (pos? x)), :val -1, :via [], :in [0]})

;; :distinct option pred is not resolved:
(::s/problems (s/explain-data (s/coll-of pos? :distinct true) [-1 -1]))
[{:path [], :pred distinct?, :val [-1 -1], :via [], :in []}]

map-of and every-kv do not have this issue. The :count, :min-count, :max-count, and :kind options do correctly produce resolved :preds.

Patch: clj-2168.patch

Activity

Hide
Shogo Ohta added a comment -

The same problem happens with s/every.

Show
Shogo Ohta added a comment - The same problem happens with s/every.
Hide
Shogo Ohta added a comment - - edited

Oh, sorry. I meant s/every-kv, not s/every.

BTW, after looking into things around this, I found some other spec macros were putting inconsistent forms of :pred in their explain data.

For example,

(s/explain-data (s/tuple integer?) []) => (clojure.core/= (clojure.core/count %) 1)
(s/explain-data (s/& integer? even?) []) => #function[clojure.core/integer?] (not a symbol)

I'll file that as another ticket later.

Show
Shogo Ohta added a comment - - edited Oh, sorry. I meant s/every-kv, not s/every. BTW, after looking into things around this, I found some other spec macros were putting inconsistent forms of :pred in their explain data. For example, (s/explain-data (s/tuple integer?) []) => (clojure.core/= (clojure.core/count %) 1) (s/explain-data (s/& integer? even?) []) => #function[clojure.core/integer?] (not a symbol) I'll file that as another ticket later.
Hide
Alexander Kiel added a comment -
Show
Alexander Kiel added a comment - Issue https://github.com/alexanderkiel/phrase/issues/22 relates to this.

People

Vote (4)
Watch (1)

Dates

  • Created:
    Updated: