Welcome! Please see the About page for a little more info on how this works.

0 votes
in Protocols by

clojure.core/proxy does not work when one reloads namespace containing defprotocol.

E.g. one can't reload the following file without triggering an error:


(ns foo.baz)

(defprotocol Hello
(hello [this]))

(def hello-proxy
(proxy [foo.baz.Hello] []

(hello []
  (println "hello world"))))

(hello hello-proxy)

Saving the above as foo/baz.clj, I get the following error:

$ rlwrap java -cp target/clojure-1.8.0-master-SNAPSHOT.jar:. clojure.main Clojure 1.8.0-master-SNAPSHOT user=> (require 'foo.baz :reload) hello world nil user=> (require 'foo.baz :reload) CompilerException java.lang.IllegalArgumentException: No implementation of method: :hello of protocol: #'foo.baz/Hello found for class: foo.baz.proxy$java.lang.Object$Hello$6f95b989, compiling:(foo/baz.clj:11:1)

I'm using the current git master (commit 5cfe5111ccb5afec4f9c73), but clojure 1.7 has the same problem.

The problem is that proxy-name only uses the interface names as a key. These names do not change when reloading the namespace, but the interfaces themself are new.

I'm going to attach a short patch which fixes that issue for me.

2 Answers

0 votes

Comment made by: schmir

I'm not sure how this interacts with AOT compilation.

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-1864 (reported by schmir)