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

CompileStatic + static inner class + EqualsAndHashCode gives VerifyError in equals

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: Static compilation
    • Labels:
      None

      Description

      import groovy.transform.CompileStatic
      import groovy.transform.EqualsAndHashCode
      
      @CompileStatic
      class Parent {
          List<Integer> getInts() { [0] }
      
          @EqualsAndHashCode
          static class Child {
              List<Integer> ints
          }
      }
      
      println GroovySystem.version
      println new Parent.Child()
      

      The key is the inner class having a property matching the parent's.

      Result:

      2.4.6
      java.lang.VerifyError: (class: Parent$Child, method: equals signature: (Ljava/lang/Object;)Z) Incompatible object argument for function call
      

      Inspecting the bytecode, I see the following:

         L13
          ALOAD 0
          INVOKEVIRTUAL Parent.getInts ()Ljava/util/List;
          ALOAD 2
          INVOKEVIRTUAL Parent$Child.getInts ()Ljava/util/List;
          INVOKESTATIC org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareEqual (Ljava/lang/Object;Ljava/lang/Object;)Z
          IFNE L14
          ICONST_1
      

      It appears that the bytecode is attempting to call a method on the outer class, even though the inner class is static and there is no reason to access the outer class.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              gillius Jason Winnebeck
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: