I have encountered a problem when using deftype in Clojure. If I run the following code:
(defprotocol TestProt
(geta [this])
(getb [this]))
(deftype TestType [a b]
TestProt
(geta [this] a)
(getb [this] b))
(defn test-function [^TestType a-testtype]
(print (.geta a-testtype)))
(def test-tt (TestType. 1 1))
(test-function test-tt)
Then the compiler throws: ClassCastException MyProject.core.TestType cannot be cast to MyProject.core.TestType. Am I doing something wrong, or is this a bug? Note that if I remove the type annotation from test-function, so it's just:
(defn test-function [a-testtype]
(print (.geta a-testtype)))
Then the code works fine, but I get a warning (with warn-on-reflect enabled) about reflection, and it runs slower, which defeats the purpose of using deftype in my current use-case.
Edit: Okay, the code works in the repl, but not when I load it using ctrl-alt-s (I'm running it in Eclipse via Counterclockwise). So the problem seems to be with Eclipse or Counterclockwise.