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

Generated size() method on records performs unnecessary boxing

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0.17
    • 4.0.19, 5.0.0-alpha-6
    • None
    • None

    Description

      I have the following code:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      static void main(String[] args) {
          println(new Person("John", 42).size())
      }
      
      @CompileStatic
      record Person(String name, int age) {} 

      When checking the compiled output, the size method performs unnecessary boxing:

      @Generated
      public final int size() {
          return Integer.valueOf(2);
      }
      
      // access flags 0x11
      public final size()I
      @Lgroovy/transform/Generated;()
       L0
        ICONST_2
        INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
        INVOKEVIRTUAL java/lang/Integer.intValue ()I
        IRETURN
       L1
        LOCALVARIABLE this Lorg/example/Person; L0 L1 0
        MAXSTACK = 1
        MAXLOCALS = 1
      

      Attachments

        Activity

          People

            paulk Paul King
            paint_ninja Oscar N
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: