Reflection warning when defining multimethods with *warn-on-reflection*

7 views
Skip to first unread message

Darshan Shaligram

unread,
Mar 7, 2008, 2:50:22 PM3/7/08
to Clojure
When experimenting with Clojure multimethods and *warn-on-reflection*
on Clojure svn r725, I found that defmethod produces this warning:

Reflection warning, line: 829 - call to assoc can't be resolved.

I'm guessing a type hint to clojure.lang.MultiFn in boot.clj:829 will
fix this. The code involved (admittedly silly) was:

(def *warn-on-reflection* true)
(defmulti laborious-evenp
(fn [x] (if (zero? (rem x 2)) :even :odd)))
(defmethod laborious-evenp :even [x] true)
(defmethod laborious-evenp :odd [x] false)

(I ran this test using clojure.lang.Script.)

I'm also wondering if it would be possible to show the source file
name in addition to the line number for warnings?

Thanks,
Darshan

Rich Hickey

unread,
Mar 7, 2008, 3:49:38 PM3/7/08
to Clojure


On Mar 7, 2:50 pm, Darshan Shaligram <scinti...@gmail.com> wrote:
> When experimenting with Clojure multimethods and *warn-on-reflection*
> on Clojure svn r725, I found that defmethod produces this warning:
>
> Reflection warning, line: 829 - call to assoc can't be resolved.
>
> I'm guessing a type hint to clojure.lang.MultiFn in boot.clj:829 will
> fix this. The code involved (admittedly silly) was:
>
> (def *warn-on-reflection* true)
> (defmulti laborious-evenp
> (fn [x] (if (zero? (rem x 2)) :even :odd)))
> (defmethod laborious-evenp :even [x] true)
> (defmethod laborious-evenp :odd [x] false)
>

I've added the needed type hints to make this warning go away.

> I'm also wondering if it would be possible to show the source file
> name in addition to the line number for warnings?
>

Eventually, although, as in this case, it means communicating line #s
from macros, something I haven't gotten around to yet.

Rich
Reply all
Reply to author
Forward
0 new messages