Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9336

Shift operator used in field initial value expression causing incorrect type conversion

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.0.0-rc-3
    • Component/s: None
    • Labels:
      None

      Description

      Consider the following:

      class C {
        public static final double D = 2 << 16 - 1
      }
      

      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:

      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)
      

      I think that the right side of any shift operation should be converted to int (not double in this case).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                emilles Eric Milles
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h