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

@CompileStatic throws verify error using power operator

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-rc-3
    • 2.0-rc-4
    • Static compilation
    • None

    Description

      The following code produces a VerifyError

      int squarePlusOne(int num) {
         num ** num + 1
      }
      assert squarePlusOne(2) == 5
      

      The reason is that the helper power method takes a Long as first argument, but we call it with an Integer:

      squarePlusOne(I)I
      00000 LTestScripttestPowerShouldNotThrowVerifyError0; I  :  :     ILOAD 1
      00001 LTestScripttestPowerShouldNotThrowVerifyError0; I  : I  :     INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
      00002 LTestScripttestPowerShouldNotThrowVerifyError0; I  : Integer  :     ILOAD 1
      00003 LTestScripttestPowerShouldNotThrowVerifyError0; I  : Integer I  :     INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
      00004 LTestScripttestPowerShouldNotThrowVerifyError0; I  : Integer Integer  :     INVOKESTATIC org/codehaus/groovy/runtime/DefaultGroovyMethods.power (Ljava/lang/Long;Ljava/lang/Integer;)Ljava/lang/Number;
      00005 ?     :     ICONST_1
      00006 ?     :     INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
      00007 ?     :     INVOKESTATIC org/codehaus/groovy/runtime/dgmimpl/NumberNumberPlus.plus (Ljava/lang/Number;Ljava/lang/Number;)Ljava/lang/Number;
      00008 ?     :     INVOKESTATIC org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.intUnbox (Ljava/lang/Object;)I
      00009 ?     :     IRETURN
      00010 ?     :     LDC 0
      00011 ?     :     IRETURN
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            melix Cédric Champeau
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment