I am not sure why you say "new primitive type hints".  Primitive type hints
have been around for several Clojure released versions, 1.6.0 and earlier.

The error you are seeing is because of a property of the Clojure compiler
that as far as I know is not documented.  I asked back in Nov 2014 whether
it was, but didn't get any response [1].

Clojure eval's type tags on def'd names, and since 'long', 'longs', 'int',
'ints', etc. are also the names of functions in clojure.core, type tags of
the kind you tried to use, _when applied to the def'd or defn'd symbols_,
are treated as the values of those functions, and in most cases are ignored
by the Clojure compiler.  You found a case where they are not ignored.
This is not new in Clojure 1.7.0-beta2.  I verified your example gives the
same results with Clojure 1.6.0, and I would guess it would also do that
for a few earlier Clojure releases, too.

Either do this:

(defn ^{:tag 'longs} init-state []  (long-array 1))

or put the type tag on the argument vector instead:

(defn init-state ^longs []  (long-array 1))

The latest release of the Eastwood lint tool [2] will warn about type tags
of the kind you used:

(defn ^longs init-state []  (long-array 1))

Andy


[1] https://groups.google.com/d/msg/clojure-dev/u3mcy7iiQ40/ZUP8nglwVDsJ
[2] https://github.com/jonase/eastwood

On Fri, May 1, 2015 at 11:13 AM, <shlomivak...@gmail.com> wrote:

> I tried playing around with the new primitive type hints and got the
> following weird behavior on [org.clojure/clojure "1.7.0-beta2"]:
>
> (defn ^longs init-state []  (long-array 1))
>
> (defn ^long store-state [^longs c ^long a] (aset c 0 a))
>
> running the following line resulted in an exception:
>
> (let [x (init-state)]
>   (store-state x 5))
>
> 1. Caused by java.lang.VerifyError
>    (class: clojure_7/core$eval13270, method: invoke signature:
>    ()Ljava/lang/Object;) Unable to pop operand off an empty stack
>
>                     Class.java:   -2
>  java.lang.Class/getDeclaredConstructors0
>                     Class.java: 2671
>  java.lang.Class/privateGetDeclaredConstructors
>                     Class.java: 3075  java.lang.Class/getConstructor0
>                     Class.java:  412  java.lang.Class/newInstance
>                  Compiler.java: 4843  clojure.lang.Compiler$ObjExpr/eval
>                  Compiler.java: 6791  clojure.lang.Compiler/eval
>                  Compiler.java: 7237  clojure.lang.Compiler/load
>                           REPL:    1  reverse-index.main/eval13258
>                  Compiler.java: 6792  clojure.lang.Compiler/eval
>                  Compiler.java: 6755  clojure.lang.Compiler/eval
>                       core.clj: 3079  clojure.core/eval
>                       main.clj:  240  clojure.main/repl/read-eval-print/fn
>                       main.clj:  240  clojure.main/repl/read-eval-print
>                       main.clj:  258  clojure.main/repl/fn
>                       main.clj:  258  clojure.main/repl
>                    RestFn.java: 1523  clojure.lang.RestFn/invoke
>         interruptible_eval.clj:   58
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
>                       AFn.java:  152  clojure.lang.AFn/applyToHelper
>                       AFn.java:  144  clojure.lang.AFn/applyTo
>                       core.clj:  628  clojure.core/apply
>                       core.clj: 1866  clojure.core/with-bindings*
>                    RestFn.java:  425  clojure.lang.RestFn/invoke
>         interruptible_eval.clj:   56
>  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
>         interruptible_eval.clj:  188
>  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
>         interruptible_eval.clj:  157
>  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
>                       AFn.java:   22  clojure.lang.AFn/run
>        ThreadPoolExecutor.java: 1142
>  java.util.concurrent.ThreadPoolExecutor/runWorker
>        ThreadPoolExecutor.java:  617
>  java.util.concurrent.ThreadPoolExecutor$Worker/run
>                    Thread.java:  745  java.lang.Thread/run
>
> while the following line worked just fine:
>
> (store-state (init-state) 5)
>
> and also this works fine:
>
> (def a (init-state))
> (store-state a 5)
>
> (aget a 0) ;; 5
>
> What do you think?
>
> On Friday, April 24, 2015 at 11:27:40 AM UTC-7, Alex Miller wrote:
>>
>> Clojure 1.7.0-beta2 is now available.
>>
>> Try it via
>> - Download:
>> https://repo1.maven.org/maven2/org/clojure/clojure/1.7.0-beta2/
>> - Leiningen: [org.clojure/clojure "1.7.0-beta2"]
>>
>> Regression fixes since 1.7.0-beta1:
>>
>> 1) CLJ-1711 - structmap iterator broken
>> 2) CLJ-1709 - range wrong for step != 1
>> 3) CLJ-1713 - range chunks are not serializable
>> 4) CLJ-1698 - fix reader conditional bugs
>>
>> Additional enhancements to new features since 1.7.0-beta1:
>>
>> 1) CLJ-1703 - Pretty print #error and new public function Throwable->map
>> 2) CLJ-1700 - Reader conditionals now allowed in the REPL
>> 3) CLJ-1699 - Allow data_readers.cljc as well as data_readers.clj
>>
>> For a full list of changes since 1.6.0, see:
>> https://github.com/clojure/clojure/blob/master/changes.md
>>
>> Please give it a try and let us know if things are working (or not)!
>>
>> - Alex
>>
>>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to