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

Statically compiled calls to private outer class methods fail with multiple levels of nesting

    XMLWordPrintableJSON

    Details

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

      Description

      Example:

      @groovy.transform.CompileStatic
      class A {
          private int bar() { 123 }
          
          class B {
              int testInner() { new C().barInner() }
              
              class C {
                  int barInner() { bar() }
              }
          }
      
          int test() {
              new B().testInner()
          }
      }
      assert new A().test() == 123
      

      The code above fails with the following error at runtime:

      org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'A$B@4c1d9d4b' with class 'A$B' to class 'A'
      

      This occurs because the bridge method owner for an 'implicit this' private method call is assumed to be the immediate outer class.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                shils Shil Sinha
                Reporter:
                shils Shil Sinha
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: