You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/01/11 18:32:00 UTC
[jira] [Assigned] (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 ]
Eric Milles reassigned GROOVY-9336:
-----------------------------------
Assignee: Eric Milles
> 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
>
> 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)