We're updating the issue view to help you get more done. 

[core.specs] Check early if let binding vector is even

Description

If you miss a value in the let binding vector, Spec will return a rather verbose and misguiding message:

1 2 3 4 5 6 user=> (require '[clojure.spec.alpha :as s] '[clojure.core.specs.alpha :as cs]) user=> (s/explain ::cs/bindings '[a #_1 b 2]) In: [2] val: 2 fails spec: :clojure.core.specs.alpha/local-name at: [:binding :sym] predicate: simple-symbol? In: [2] val: 2 fails spec: :clojure.core.specs.alpha/seq-binding-form at: [:binding :seq] predicate: vector? In: [2] val: 2 fails spec: :clojure.core.specs.alpha/map-bindings at: [:binding :map] predicate: coll? In: [2] val: 2 fails spec: :clojure.core.specs.alpha/map-special-binding at: [:binding :map] predicate: map?

The crux of the problem here is the odd number of parameters in the binding. Spec gets to it anyway, but if it first finds a parameter that is an invalid binding form, it will bark at that instead. With the suggested patch, the error looks like:

1 2 user=> (s/explain ::cs/bindings '[a #_1 b 2]) val: [a b 2] fails spec: :clojure.core.specs.alpha/bindings predicate: even-number-of-forms?

Patch: clj-2376-2.patch

Environment

None

Status

Assignee

Unassigned

Reporter

Alexander Yakushev

Labels

Approval

Vetted

Patch

Code

Fix versions

Affects versions

Release 1.9

Priority

Minor