Thanks Andy, I was just writing a reply clarifying that point.
To David, Ambrose & all:
I mispoke on my first post, tools.analyzer and all the passes on that
library have no assumption whatsoever about :tag, in fact tools.analyzer
never deals with :tag at all.
I understand and agree that CLJS has different needs and :tag in CLJS
will obviously NEVER be a Class.
It goes further than that, c.t.a.passes.jvm/infer-tag itself
doesn't care at all whether :tag is a Class or something else, I'll
probably move some parts of that pass in a tools.analyzer pass as I'm
sure it will be useful for local tag inference on a CLJS port.
What's actually throwing an exception when :tag cannot be resolved to a
class is the c.t.a.passes.jvm/validate pass, this pass also throws on
method not found, on invokes with wrong arity etc.
So, my *strictly* clojure JVM related question is:
Given that it's stated in several pages on
clojure.org that :tag should
be used as a hint to the compiler, is it wrong to assume that tag should
*always* have as a val something (either a Symbol, a String or a Class)
that can resolve to a Class and assume that the current Clojure
behaviour of allowing aribitrary :tag values in some cases should be
considered an implementation detail (just like (keyword " ") works)?
Some examples where arbitrary :tag throws:
user=> (def ^foo a)
CompilerException java.lang.RuntimeException: Unable to resolve symbol:
foo in this context, compiling:(NO_SOURCE_PATH:1:1)
user=> (let [^foo a []] (.hashCode a))
CompilerException java.lang.IllegalArgumentException: Unable to resolve
classname: foo, compiling:(NO_SOURCE_PATH:4:18)
user=> (let [a []] (.hashCode ^foo a))
CompilerException java.lang.IllegalArgumentException: Unable to resolve
classname: foo, compiling:(NO_SOURCE_PATH:7:13)
user=> (fn ^foo [])
CompilerException java.lang.IllegalArgumentException: Unable to resolve
classname: foo, compiling:(NO_SOURCE_PATH:11:1)
user=> (fn [^foo x])
CompilerException java.lang.IllegalArgumentException: Unable to resolve
classname: foo, compiling:(NO_SOURCE_PATH:12:1)
user=> (deftype x [] Object (equals [this ^foo that] nil))
CompilerException java.lang.IllegalArgumentException: Unable to resolve
classname: foo, compiling:(NO_SOURCE_PATH:3:1)
user=> (deftype x [^foo a])
CompilerException java.lang.IllegalArgumentException: Unable to resolve
classname: foo, compiling:(NO_SOURCE_PATH:4:1)
Thanks,
Nicola