Welcome! Please see the About page for a little more info on how this works.

0 votes
in Spec by

If we try to pass a non-keyword to clojure.spec/keys or clojure.spec/keys** on the named argument :opt or :opt-un we get an assertion error:

`
(spec/valid? (spec/keys :opt ['a 5]) {})
;1. Caused by java.lang.AssertionError
; Assert failed: all keys must be namespace-qualified keywords
; (every? (fn* [p1__13667#] (c/and (keyword? p113667#) (namespace
; p1
13667#))) (concat req-keys req-un-specs opt opt-un))

(spec/valid? (spec/keys :opt-un ['a 5]) {})
;1. Caused by java.lang.AssertionError
; Assert failed: all keys must be namespace-qualified keywords
; (every? (fn
[p1__13667#] (c/and (keyword? p113667#) (namespace
; p1
13667#))) (concat req-keys req-un-specs opt opt-un))
`

But if we do the same for the named arguments :req and :req-un the arguments are silently ignored and the call to keys returns a spec matching any map without any requirements:

(spec/valid? (spec/keys :req ['a 5]) {}) => true (spec/valid? (spec/keys :req-un ['a 5]) {}) => true (spec/valid? (spec/keys* :req ['a 5]) {}) => true (spec/valid? (spec/keys* :req-un ['a 5]) {}) => true

An assertion should probably be thrown for the :req(-un)? args too.

1 Answer

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2154 (reported by rovanion)
...