methodical icon indicating copy to clipboard operation
methodical copied to clipboard

`defmulti` should throw an error with invalid args

Open camsaul opened this issue 5 years ago • 0 comments

This code

(m/defmulti multifn
  {:arglists '([x y z])}
  (fn [x y _]
    [(keyword x) (keyword y)]))

;; oops, I should have used defmethod!
(m/defmulti multifn :default
  [x y z]
  :ok)

(multifn :x :y :z)

results in this Exception:

1. Unhandled java.lang.IllegalArgumentException
   Wrong number of args passed to keyword: :default

              Keyword.java:   98  clojure.lang.Keyword/throwArity
              Keyword.java:  149  clojure.lang.Keyword/invoke
              standard.clj:  117  methodical.impl.dispatcher.standard.StandardDispatcher/dispatch_value
              standard.clj:   22  methodical.impl.standard/invoke-multifn
              standard.clj:   30  methodical.impl.standard.StandardMultiFn/invoke

The Exception is only thrown after attempting to invoke the method.

Not sure if this is because the logic to skip redefs is preventing the second defmulti or not, but that should throw an Exception right away instead of when invoking.

camsaul avatar Apr 15 '20 03:04 camsaul