camsaul / methodical

Functional and flexible multimethods for Clojure. Nondestructive multimethod construction, CLOS-style aux methods and method combinations, partial-default dispatch, easy next-method invocation, helpful debugging tools, and more.
Eclipse Public License 2.0
292 stars 19 forks source link

Illegal class name from array class dispatch value #81

Closed glchapman closed 2 years ago

glchapman commented 2 years ago

@camsaul: I have a data reader which allows me to read Java array class as a symbol. So, for example:

user=> (= '#glc/symof(Object[]) (symbol "[Ljava.lang.Object;"))
true

I wanted to use this to produce a dispatch value matching all Object arrays (String[], List[], etc.). Unfortunately, this:

(require '[methodical.core :as m])
(m/defmulti objarray? class)
(m/defmethod objarray? :default [_] false)
(m/defmethod objarray? #glc/symof(Object[]) [_] true)

produces the error:

Syntax error (ClassFormatError) compiling fn* at (REPL:1:1).
Illegal class name "user$objarray_QMARK__primary_method__LBRACK_Ljava_lang_Object;"

It seems Clojure's munge (used by macros/dispatch-val-name does not handle ';'.

The above objarray? will work with Clojure's multimethods; perhaps you can add a fix for this (obscure) case?

camsaul commented 2 years ago

@glchapman would you mind opening a quick PR for this? I'll merge it and do a new release if you do

glchapman commented 2 years ago

I'd completely forgotten about this issue, and, looking at it again, I think I shouldn't have filed it as it is too obscure to be worth spending time on (also, as it turns out, I'm not using methodical in any projects currently). Anyway, I'm closing the issue; I apologize for wasting your time.