You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/01/27 00:45:01 UTC

[jira] [Closed] (GROOVY-9336) Shift operator used in field initial value expression causing incorrect type conversion

     [ https://issues.apache.org/jira/browse/GROOVY-9336?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-9336.
-----------------------------

> Shift operator used in field initial value expression causing incorrect type conversion
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-9336
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9336
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 3.0.0-rc-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Consider the following:
> {code:groovy}
> class C {
>   public static final double D = 2 << 16 - 1
> }
> {code}
> User has omitted parentheses around "2 << 16" and so this is evaluated as {{2 << (16 - 1)}}.  During inline constant conversion ({{ExpressionUtils.transformInlineConstants}}), the right side of the shift operator is converted to a double and this results in:
> {code}
> java.lang.UnsupportedOperationException: Shift distance must be an integral type, but 15.0 (java.lang.Double) was supplied
> 	at org.codehaus.groovy.runtime.typehandling.NumberMath.leftShift(NumberMath.java:99)
> 	at org.apache.groovy.ast.tools.ExpressionUtils.transformBinaryConstantExpression(ExpressionUtils.java:113)
> {code}
> I think that the right side of any shift operation should be converted to int (not double in this case).



--
This message was sent by Atlassian Jira
(v8.3.4#803005)