I do actually have specs for spec and it would catch these. :) You can try it yourself though:
(s/def ::s/req (s/* keyword?)) (s/def ::s/req-un (s/* keyword?)) (s/def ::s/opt (s/* keyword?)) (s/def ::s/opt-un (s/* keyword?)) (s/fdef s/keys :args (s/cat :form ::s/any :env ::s/any ;; form/env unnecessary as of 1.9.0-alpha3 :opts (s/keys* :opt-un [::s/req ::s/req-un ::s/opt ::s/opt-un ::s/gen])) :ret ::s/any) (s/instrument #'clojure.spec/keys) user=> (s/keys :req ["a"]) CompilerException java.lang.IllegalArgumentException: Call to clojure.spec/keys did not conform to spec: In: [:req 0] val: "a" fails spec: :clojure.spec/req at: [:args :opts :req] predicate: keyword? :clojure.spec/args ((s/keys :req ["a"]) nil :req ["a"]) , compiling:(NO_SOURCE_PATH:26:1) user=> (s/keys :req [5]) CompilerException java.lang.IllegalArgumentException: Call to clojure.spec/keys did not conform to spec: In: [:req 0] val: 5 fails spec: :clojure.spec/req at: [:args :opts :req] predicate: keyword? :clojure.spec/args ((s/keys :req [5]) nil :req [5]) , compiling:(NO_SOURCE_PATH:27:1) On Wednesday, May 25, 2016 at 1:29:57 PM UTC-5, Gary Trakhman wrote: > > It seems like the :req impls should go further to disallow trash input, > it's not immediately clear that they only allow namespaced keywords. > > For example: > > (s/valid? (s/keys :req ["a"]) {:a 5}) > true > > (s/valid? (s/keys :req [5]) {:a 5}) > true > > What ends up happening in practice, is (filter keyword? (flatten req)), > which is suspect. > > Could/should spec be used to check itself? That's the lisp way, after > all. To do so here, we might need more map-checking builtins than s/keys. > -- 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.