Confusing compiler error in defrecord and deftype.

143 views
Skip to first unread message

Travis Hoffman

unread,
Jul 20, 2010, 3:00:07 PM7/20/10
to Clojure
Hello, I've come across the following compiler error in defrecord and
deftype:

java.lang.RuntimeException: java.lang.ClassCastException:
clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol
(test.clj:0)

To generate the error, evaluate the following code:

(ns test)

(defrecord TestRecord [afield bfield cfield]
(printc [_] (println cfield)))

(deftype TestType [afield bfield cfield]
(printc [_] (println cfield)))

The error I believe I should be getting is something like this:

java.lang.IllegalArgumentException: Can't define method not in
interfaces: printc (test.clj:8)

Which can be generated with the following code:

(ns test)

(defprotocol TestProtocol
""
(printa [testtype] "")
(printb [testtype] ""))

(defrecord TestRecord [afield bfield cfield]
TestProtocol
(printa [_] (println afield))
(printb [_] (println bfield))
(printc [_] (println cfield)))

(deftype TestType [afield bfield cfield]
TestProtocol
(printa [_] (println afield))
(printb [_] (println bfield))
(printc [_] (println cfield)))

I haven't found, on Assembla, to submit a ticket, otherwise I would
have done so. :-)

Cheers,
Travis

Stuart Halloway

unread,
Jul 20, 2010, 3:58:32 PM7/20/10
to clo...@googlegroups.com
Hi Travis,

As you noticed, there is no error handling for the case where you pass a bad spec to defrecord. In your example, the spec has method bodies but no protocol-or-interface-or-Object.

I have created a ticket for this at https://www.assembla.com/spaces/clojure/tickets/405-better-error-messages-for-bad-defrecord-calls.

The ticket comment includes instructions for how and where to patch this. If anyone has been frustrated by Clojure's error messages and is looking for an easy way to contribute, have at it. :-)

Stu

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Baishampayan Ghose

unread,
Jul 22, 2010, 7:41:51 AM7/22/10
to clo...@googlegroups.com
Stuart Halloway wrote:
> I have created a ticket for this at https://www.assembla.com/spaces/clojure/tickets/405-better-error-messages-for-bad-defrecord-calls.
>
> The ticket comment includes instructions for how and where to patch this. If anyone has been frustrated by Clojure's error messages and is looking for an easy way to contribute, have at it. :-)

Do I need to have my CA on file before I can contribute? I have them
signed and ready to ship anyway...

Regards,
BG

--
Baishampayan Ghose <b.g...@ocricket.com>
oCricket.com

Reply all
Reply to author
Forward
0 new messages