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

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.7
    • 2.4.8
    • Static compilation
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: