Fork me on GitHub
#clojure-spec
<
2017-08-21
>
Alex Miller (Clojure team)00:08:28

@souenzzo multimethods are not currently support with spec fdef

mgrbyte13:08:50

@alexmiller Does ☝️ also hold for protocols? currently trying to spec a protocol fn that dispatches on type with s/or and not succeeding...

Alex Miller (Clojure team)14:08:22

functions that can’t be instrumented right now include: multimethods, protocols, inline functions, and primitive type hinted functions

Alex Miller (Clojure team)14:08:33

some of those are fixable, some aren’t (easily)

mgrbyte15:08:08

attempting to spec a fn that has one argument, but can accept either a string or keyword, my attempt:

(s/fdef species->ident
        :args (s/or :string-val string? :keyword-val keyword?)
        :ret keyword?)
(defn species->ident [s-or-kw]
  (-species->ident s-or-kw))
(clojure.spec.test.alpha/check 'species->ident) gives the error (snipped):
:failure #error {
 :cause "Don't know how to create ISeq from: clojure.lang.Keyword"
 :via
 [{:type java.lang.IllegalArgumentException
   :message "Don't know how to create ISeq from: clojure.lang.Keyword"
   :at [clojure.lang.RT seqFrom "RT.java" 547]}]
I think I'm probably using the wrong spec for args; any pointers please?

mgrbyte15:08:52

(assuming it's safe to spec a regular fn that delegates to a protocol fn)

andrewmcveigh15:08:31

You'll need something like

(s/fdef species->ident
        :args (s/cat :arg1 (s/or :string-val string? :keyword-val keyword?))
        :ret keyword?)

andrewmcveigh15:08:54

:args will always be a sequence