sastanin
sastanin

Reputation: 41541

Can't type hint a local with a primitive initializer

Could someone explain me this error:

user> (let [^int i 3] i)
CompilerException java.lang.UnsupportedOperationException: Can't type hint a local with a primitive initializer, compiling:(NO_SOURCE_PATH:1)

I don't understand,

Upvotes: 8

Views: 1688

Answers (1)

Ankur
Ankur

Reputation: 33657

This exception is thrown by the compiler from this line. Basically, if you use an expression which is a primitive constant or something that can be evaluated at compile time to be a primitive constant, like: (+ 1 10), the compiler can detect the type of the object itself and doesn't need type hinting. Check the getJavaClass and hasJavaClass methods in the same class in which the earlier link points to. These methods check if the expression is primitive then get the class from the expression itself, otherwise use type hinting if provided.

Upvotes: 6

Related Questions