clj-kondo

https://github.com/clj-kondo/clj-kondo
2021-01-08T12:39:08.234400Z

I found a “problem” with defmethod because defmethod expects & fn-tail it is possible to set local binding for the function that implement that particular method. but clj-kondo give me an error for such case

borkdude 2021-01-08T12:44:54.234900Z

@delaguardo Can you post this code as text instead of screenshot?

2021-01-08T12:45:30.235200Z

(require '[clojure.string :as string])

(defmulti example :tag)

(defmethod example :node
  f
  ([] "NODE: ")
  ([{:keys [children]}]
   (str (f) (string/join " " (map example children)))))

(defmethod example :leaf
  f
  ([] "LEAF: ")
  ([{:keys [value]}]
   (str (f) value)))
sure

2021-01-08T12:47:28.236700Z

this is definitely an edge case which I never saw in real examples so I came here to check if this is something that should be addressed in clj-kondo.

borkdude 2021-01-08T12:48:21.237100Z

ah, so multimethods fns can be named. didn't know that So a working example would be:

(prn
 (example {:tag :node :children [{:tag :leaf :value 1}]}))

borkdude 2021-01-08T12:48:49.237500Z

it also works with bb :)

$ bb /tmp/mm.clj
"NODE: LEAF: 1"

borkdude 2021-01-08T12:49:08.237700Z

Feel free to make an issue about this

borkdude 2021-01-08T12:54:01.238200Z

you can ignore the false positive with #_:clj-kondo/ignore (f)

borkdude 2021-01-08T13:04:52.238800Z

:thumbsup: