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

VerifyError using @CompileStatic and assertEquals

    XMLWordPrintableJSON

Details

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

    Description

      The following code produces a VerifyError:

      import static org.junit.Assert.*;
      import groovy.transform.CompileStatic;
      
      @CompileStatic
      class CompilerBugs {
      
        public static void main(String[] args) {
          int expected = 0
          assertEquals(expected, args.length)
        }
      
      }
      

      Bytecode shows that the selected method is incorrect:

      public static void main(java.lang.String[]);
        Code:
         0:   iconst_0
         1:   istore_1
         2:   iload_1
         3:   pop
         4:   iload_1
         5:   invokestatic    #41; //Method
      java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
         8:   ldc     #43; //class "[Ljava/lang/Object;"
         10:  invokestatic    #49; //Method
      org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
         13:  checkcast       #43; //class "[Ljava/lang/Object;"
         16:  iconst_1
         17:  anewarray       #4; //class java/lang/Object
         20:  dup
         21:  iconst_0
         22:  aload_0
         23:  arraylength
         24:  aastore
         25:  invokestatic    #55; //Method
      org/junit/Assert.assertEquals:([Ljava/lang/Object;[Ljava/lang/Object;)V
         28:  aconst_null
         29:  pop
         30:  return
      

      Attachments

        Activity

          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: