Re: Array type hints in 1.3
I reread your original post, sorry I saw that you managed to declare type constrained methods. Then, what was your question about? Type hinting for arguments works as well: (definterface Name (^[S method [^[S short-arg])) (def p (proxy [Name] [] (method [^[S short-arg] short-arg))) (.method p (short-array [(short 10) (short 11)])) Interesting, I didn't actually check the runtime behavior. Decompiler says, the emitted class names are bogus. Do you mean the interface name? JVM probably doesn't cast on return, so it slips through. Have you tried hinting an argument? I'm not sure what happens in case of arrays, but for simple return types it definitely does the check. (def p (proxy [Comparable] [] (^int compareTo [arg] arg) ;;doesn't matter (^String toString [] 10))) ;;will throw ClassCastException on invocation. Cheers, Ivan. -- 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
Re: Array type hints in 1.3
2011/10/22 Ivan Koblik ivankob...@gmail.com: I reread your original post, sorry I saw that you managed to declare type constrained methods. Then, what was your question about? I just reread it too and realized I didn't make a whole lot of sense. I'll try again: Do you mean the interface name? Compiling the following snippet: (definterface A (^[S smethod [^[S arg]) (^shorts method [^shorts arg])) Yields the following class definition: public abstract interface A { public abstract [S smethod([S arg); public abstract short[] method(short[] arg); } This code comes from a decompiler. Note, that it refers to a class, literally named [S, while the other hint (derived from ^shorts) gets demangled as short[]. Eclipse agrees with that notion. What I realized only now, is that the runtime checker doesn't seem to care and still takes it as a short array. It would still be interesting, why the difference in unmangling? Anyway, that leaves [L; arrays and constructor decorations to be desired. Is there a way to do them? I'm not sure what happens in case of arrays, but for simple return types it definitely does the check. Then it's supposed to check arrays too, since even object arrays are not subject to type erasure. Which is the reason we need to be able to declare them when talking to java. thanks for helping me getting this straight kind regards -- __ Herwig Hochleitner -- 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
Re: Array type hints in 1.3
Another annotation bug: Annotations on gen-class in an ns form, like (ns foo (:gen-class ^{Singleton {}} foo.ClassName)) don't seem to work. -- __ Herwig Hochleitner -- 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
Re: Array type hints in 1.3
Hello Herwig, I checked the patch you linked to in your original post, and it doesn't seem that type hinting for native arrays of Objects is supported, that is the [L type. Native arrays of native types work quite well. (definterface Name (^[S method [])) ;;returns array of shorts (def p (proxy [Name] [] (method [] (short-array [(short 10) (short 1)] ;;method returns short[2] (.method p) ;; returns #short[] [S@1911540 Cheers, Ivan. On 21 October 2011 23:02, Herwig Hochleitner hhochleit...@gmail.com wrote: Another annotation bug: Annotations on gen-class in an ns form, like (ns foo (:gen-class ^{Singleton {}} foo.ClassName)) don't seem to work. -- __ Herwig Hochleitner -- 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 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
Re: Array type hints in 1.3
Just found another one: You can't annotate constructors of gen-class. 2011/10/22 Ivan Koblik ivankob...@gmail.com: Hello Herwig, I checked the patch you linked to in your original post, and it doesn't seem that type hinting for native arrays of Objects is supported, that is the [L type. Yes. It should be. Native arrays of native types work quite well. (definterface Name (^[S method [])) ;;returns array of shorts (def p (proxy [Name] [] (method [] (short-array [(short 10) (short 1)] ;;method returns short[2] (.method p) ;; returns #short[] [S@1911540 Interesting, I didn't actually check the runtime behavior. Decompiler says, the emitted class names are bogus. JVM probably doesn't cast on return, so it slips through. Have you tried hinting an argument? kind regards -- __ Herwig Hochleitner -- 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
Array type hints in 1.3
Hi, definterface has the ability to type methods. http://dev.clojure.org/jira/browse/CLJ-737 and its attached patch http://dev.clojure.org/jira/secure/attachment/10119/definterface-array-fix-with-tests.patch suggest, that you should be able specify array types too. When I tried it (in 1.3), however, it didn't work: (definterface Name (^[Ljava.lang.String; method [])) Method method in class aserver/entity/device/Name has illegal signature ()L[Ljava/lang/String;; [Thrown class java.lang.ClassFormatError] Primitive array hints do compile, the compiled code refers to a class named by the literal string though; hinting with ^longs, .. works: (definterface Name (^[J method [^longs arg])) // looking into the .class file with JD http://java.decompiler.free.fr/ public abstract [J getPushes(long[] arg); Did I do something wrong? kind regards -- __ Herwig Hochleitner -- 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