griffinbank / rules_clojure

Apache License 2.0
53 stars 8 forks source link

compile-time use of `construct-proxy`/`definterface` etc. doesn't work due to ClassLoader #51

Open SevereOverfl0w opened 8 months ago

SevereOverfl0w commented 8 months ago

Clojure assumes that clojure.lang.Compiler/LOADER is a DynamicClassLoader in a few places, but rules-clojure.persistentClassLoader is what's set to the ClassLoader instead. This causes the compilation step to fail. Compiling a namespace referencing a namespace containing (def foo (get-proxy-class ExceptionInfo)) should reproduce the error, with the message :cause class rules_clojure.persistentClassLoader cannot be cast to class clojure.lang.DynamicClassLoader (rules_clojure.persistentClassLoader is in unnamed module of loader 'app'; clojure.lang.DynamicClassLoader is in unnamed module of loader rules_clojure.persistentClassLoader @65ff29ae)

(note: for some reason I have to put that repro in b, and then compile a which :requires b)

~/src/github.com/clojure/clojure master* 
❯ rg '\^.*DynamicClassLoader'           
src/clj/clojure/genclass.clj
722:      (.defineClass ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER)

src/clj/clojure/repl/deps.clj
32:      (.addURL ^DynamicClassLoader loader u)

src/clj/clojure/core_proxy.clj
293:            (. ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode [super interfaces]))))))