This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-16
Channels
- # announcements (11)
- # beginners (184)
- # calva (91)
- # cider (68)
- # cljdoc (42)
- # cljs-dev (44)
- # clojure (228)
- # clojure-dev (1)
- # clojure-europe (3)
- # clojure-italy (4)
- # clojure-losangeles (6)
- # clojure-nl (9)
- # clojure-spec (73)
- # clojure-uk (19)
- # clojurescript (61)
- # core-async (6)
- # cursive (2)
- # datomic (11)
- # fulcro (28)
- # hyperfiddle (16)
- # leiningen (2)
- # luminus (3)
- # off-topic (19)
- # om-next (1)
- # re-frame (2)
- # reagent (12)
- # reitit (4)
- # ring-swagger (5)
- # shadow-cljs (14)
- # slack-help (6)
- # spacemacs (2)
- # tools-deps (40)
- # vim (15)
- # yada (4)
I think I’ve found a bug with instrumenting args, at least on my machine
(defn defx [key & [doc]])
(s/fdef defx
:args (s/cat :key keyword?
:doc (s/? string?)))
(st/instrument)
(defx :a "")
;; => not thrown - expected
(defx 1)
; => throws - expected
(defx 1 1)
;; => not thrown - bug
(defx 1 1 1 1)
;; => not thrown - bug
(defx :a "" 1)
;; => not thrown - bug
that spec is wrong btw
or your def is wrong, hard to tell
well, I guess maybe it’s not wrong, just hard to tell what you’re expecting
but there is a known issue with conformed values of trailing optional elements and you may be running into that
I’ve tried something like: (s/fdef defx :args (s/cat :key keyword? :opts (s/spec (s/? string?))))
, that works.
you don’t need the s/spec - & is automatically creating a sequence and there is no nested collection here
it’s weird in that the def allows N args but the spec constrains to 1 or 2
I can see that the problem reporting is failing though which I think is the bug I mentioned above
can you make a repro? this repro does work:
$ clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/test.check {:mvn/version "RELEASE"}}}' -m cljs.main -re node -r
ClojureScript 1.10.439
cljs.user=> (require '[clojure.spec.test.alpha :as stest])
nil
cljs.user=> (require '[clojure.spec.alpha :as s])
nil
(s/fdef defx
#_=> :args (s/cat :key keyword?
#_=> :doc (s/? string?)))
cljs.user/defx
cljs.user=> (defn defx [key & [doc]])
#'cljs.user/defx
cljs.user=> (stest/instrument)
[cljs.user/defx]
cljs.user=> (defx 1 1 1 1)
Error: Call to #'cljs.user/defx did not conform to spec.
ok, got it.
start repl with :static-fns
true:
clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/test.check {:mvn/version "RELEASE"}}}' -m cljs.main -co '{:static-fns true}' -re node -r
then run:
(require '[clojure.spec.alpha :as s])
(require '[clojure.spec.test.alpha :as st])
(defn defk [key & [doc]]
key)
(s/fdef defk
:args (s/cat :key keyword?
:doc (s/? string?)))
(st/instrument)
(defk 1 1)
i wouldn’t be surprised if it works, the other bug linked above only affected varargs. but let me check
at this point I’d say JIRA, but maybe @mfikes or @dnolen has something sensible to say