<!-- 
RSS generated by JIRA (4.4#649-r158309) at Wed May 22 11:39:10 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/CLJ-820/CLJ-820.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[CLJ-820] int coercion doesn&apos;t work in clojure 1.3</title>
                <link>http://dev.clojure.org/jira/browse/CLJ-820</link>
                <project id="10010" key="CLJ">Clojure</project>
                        <description>&lt;p&gt;Using the clojure git head as of 2011-07-14 (commit f704853751d02faf72bd53be599ee0be6c1da63e), int coercion doesn&apos;t work:&lt;/p&gt;

&lt;p&gt;user&amp;gt; (class (int 1))&lt;br/&gt;
java.lang.Long&lt;/p&gt;

&lt;p&gt;byte, short, double, and float coercion work fine, though:&lt;/p&gt;

&lt;p&gt;user&amp;gt; (class (byte 1))&lt;br/&gt;
java.lang.Byte&lt;br/&gt;
user&amp;gt; (class (short 1))&lt;br/&gt;
java.lang.Short&lt;br/&gt;
user&amp;gt; (class (double 1))&lt;br/&gt;
java.lang.Double&lt;br/&gt;
user&amp;gt; (class (float 1))&lt;br/&gt;
java.lang.Float&lt;/p&gt;

&lt;p&gt;Also creating integers directly works fine:&lt;/p&gt;

&lt;p&gt;user&amp;gt; (class (Integer. &quot;100&quot;))&lt;br/&gt;
java.lang.Integer&lt;br/&gt;
user&amp;gt; (class (Integer/valueOf 1))&lt;br/&gt;
java.lang.Integer&lt;br/&gt;
user&amp;gt; (class (Integer. 100))&lt;br/&gt;
java.lang.Integer&lt;/p&gt;

&lt;p&gt;This is probably related to &lt;a href=&quot;http://dev.clojure.org/jira/browse/CLJ-439&quot; title=&quot;Automatic type translation from Integer to Long&quot;&gt;&lt;del&gt;CLJ-439&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</description>
                <environment>Gentoo GNU/Linux</environment>
            <key id="14490">CLJ-820</key>
            <summary>int coercion doesn&apos;t work in clojure 1.3</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="3" iconUrl="http://dev.clojure.org/jira/images/icons/priority_major.gif">Major</priority>
                    <status id="6" iconUrl="http://dev.clojure.org/jira/images/icons/status_closed.gif">Closed</status>
                    <resolution id="2">Declined</resolution>
                                <assignee username="-1">Unassigned</assignee>
                                <reporter username="tsdh">Tassilo Horn</reporter>
                        <labels>
                    </labels>
                <created>Thu, 14 Jul 2011 08:05:40 -0500</created>
                <updated>Fri, 20 Jul 2012 16:54:48 -0500</updated>
                    <resolved>Fri, 20 Jul 2012 16:54:48 -0500</resolved>
                            <version>Release 1.3</version>
                                <fixVersion>Release 1.5</fixVersion>
                                        <due></due>
                    <votes>0</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="26571" author="paraseba" created="Fri, 15 Jul 2011 14:33:57 -0500"  >&lt;p&gt;Related documentation here: &lt;a href=&quot;http://dev.clojure.org/display/doc/Enhanced+Primitive+Support&quot;&gt;http://dev.clojure.org/display/doc/Enhanced+Primitive+Support&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;all long-or-smaller integers are boxed as Long&lt;br/&gt;
You can&apos;t use primitive coercions to force specific box types&lt;br/&gt;
Your code was broken if you were relying on that&lt;/p&gt;

&lt;p&gt;So, apparently (int) has the correct behavior. It&apos;s byte and short which should be also boxed into Longs&lt;/p&gt;</comment>
                    <comment id="26572" author="paraseba" created="Fri, 15 Jul 2011 14:34:24 -0500"  >&lt;p&gt;See also this topic in clojure-dev: &lt;a href=&quot;https://groups.google.com/d/topic/clojure-dev/fXQAYv8s0tQ/discussion&quot;&gt;https://groups.google.com/d/topic/clojure-dev/fXQAYv8s0tQ/discussion&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="26573" author="tsdh" created="Fri, 15 Jul 2011 15:00:20 -0500"  >&lt;p&gt;So to call some Java method that requires an int you have to use Integer/valueOf?&lt;/p&gt;</comment>
                    <comment id="26574" author="paraseba" created="Fri, 15 Jul 2011 15:46:02 -0500"  >&lt;p&gt;Yes, I think so&lt;/p&gt;</comment>
                    <comment id="26575" author="tsdh" created="Fri, 15 Jul 2011 16:16:11 -0500"  >&lt;p&gt;But for what are the coercion functions now good for?  I mean, &lt;a href=&quot;http://clojure.org/java_interop#Java&quot;&gt;http://clojure.org/java_interop#Java&lt;/a&gt; Interop-Coercions states:&lt;/p&gt;

&lt;p&gt;  &quot;At times it is necessary to have a value of a particular primitive type. These coercion functions yield a value of the indicated type as long as such a coercion is possible: bigdec bigint boolean byte char double float int long num short&quot;&lt;/p&gt;

&lt;p&gt;That&apos;s exactly my use case which is not supported anymore.&lt;/p&gt;</comment>
                    <comment id="26576" author="paraseba" created="Fri, 15 Jul 2011 23:09:37 -0500"  >&lt;p&gt;(int) (char) etc. are not intended to return boxed types, they always return primitive types. If you want boxed types you can use (num). When you do (class (int 42)) you are casting the long 42 to a int and then boxing it into a Long to get its class.&lt;/p&gt;

&lt;p&gt;For short and byte, I don&apos;t know, I think there is a bug, (class (short 42)) should be Short.&lt;/p&gt;</comment>
                    <comment id="26577" author="tsdh" created="Sat, 16 Jul 2011 07:13:07 -0500"  >&lt;p&gt;&lt;cite&gt;(int) (char) etc. are not intended to return boxed types, they always return primitive types.&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;Thank you, Sebasti&#225;n, that made it clear and unveiled the problem at my side.  When I did&lt;/p&gt;

&lt;p&gt;  &lt;tt&gt;(set-value! foo :position (int 17))&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;I got the exception &quot;java.lang.Long cannot be cast to java.lang.Integer&quot;.  set-value! is a protocol function extended on the java types of the java library I&apos;m interacting with.  Eventually, it&apos;ll call &lt;tt&gt;(doto foo (.setAttribute &quot;position&quot; (mutable &amp;lt;providedVal&amp;gt;))&lt;/tt&gt;, where mutable is yet another protocol function that converts clojure collections to the libraries counterparts and does nothing for primitive types.&lt;/p&gt;

&lt;p&gt;Now, although (int 17) returns an unboxed int, these two indirections box it into a Long again and the java setter is called with that leading to the error.&lt;/p&gt;

&lt;p&gt;  &lt;tt&gt;(set-value! foo :position (Integer/intValue 17))&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;circumvents the issue, because here you directly get an int boxed as Integer.&lt;/p&gt;

&lt;p&gt;&lt;cite&gt;If you want boxed types you can use (num).&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;Well, I want a boxed value of a certain type, like Integer.&lt;/p&gt;

&lt;p&gt;&lt;cite&gt;For short and byte, I don&apos;t know, I think there is a bug, (class (short 42)) should be Short.&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;Should or should not?  Currently, for all primitive types &amp;lt;primType&amp;gt;, the call &lt;tt&gt;(class (&amp;lt;primType&amp;gt; &amp;lt;val&amp;gt;))&lt;/tt&gt; returns the wrapper class corresponding to &amp;lt;primType&amp;gt; with the exception of int where you get a Long instead of an Integer.  That&apos;s totally surprising and caused me to file this bug report.&lt;/p&gt;</comment>
                    <comment id="28611" author="hircus" created="Sat, 26 May 2012 12:55:00 -0500"  >&lt;p&gt;This is fixed in 1.4.0 &amp;#8211; could one of the screeners confirm this, and maybe close the issue?&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                                                                            </customfields>
    </item>
</channel>
</rss>