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

@CompileStatic does not use bridge methods for keyed map access

    XMLWordPrintableJSON

Details

    Description

      Extracted from GROOVY-9695:

      import java.util.regex.Pattern
      import org.junit.Test
      import groovy.transform.CompileStatic
      
      class Example {
      
          @Test
          void testBaseListClass() {
              new Base().checkList()
          }
      
          @Test
          void testChildListClass() {
              new Child().checkList()
          }
      
          @Test
          void testBaseMapClass() {
              new Base().checkMap()
          }
      
          @Test
          void testChildMapClass() {
              new Child().checkMap()
          }
      
      }
      
      @CompileStatic
      class Base {
          private static final Pattern PATTERNS = ~/.*Test/
      
          def checkList() {
              List failures = []
      
              def closure = {
                  failures << PATTERNS.pattern()
              }
              closure()
          }
      
          def checkMap() {
              Map failures = [:]
      
              def closure = {
                  failures[PATTERNS.pattern()] = 1
              }
              closure()
          }
      }
      
      class Child extends Base {
      
      }
       

      For the list it works fine (Procyon Decompiler)

          public Object doCall(final Object it) {
              return DefaultGroovyMethods.leftShift((List<String>)ScriptBytecodeAdapter.castToType(this.failures.get(), List.class), Base.pfaccess$0((Base)null).pattern());
          }
       

      For the map it doesn't use the bridge method (Procyon Decompiler)

          public Object doCall(final Object it) {
              final int n = 1;
              DefaultGroovyMethods.putAt((Map<String, Integer>)ScriptBytecodeAdapter.castToType(this.failures.get(), Map.class), ((Pattern)this.getProperty("PATTERNS")).pattern(), n);
              return n;
          }
       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              leonard84 Leonard Brünings
              Votes:
              0 Vote for this issue
              Watchers:
              3 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 - 20m
                  20m