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

Outer class method call failure with @CompileStatic

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.6
    • 2.3.1, 2.2.3
    • Static compilation
    • None

    Description

      Take the following code:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class Outer {
          private int outerField = 1
          private int outerMethod() { 2 }
          int outerProperty = 3
          class Inner {
              void assertions() {
                  assert outerField == 1            // #1
                  assert outerMethod() == 2         // #2
                  assert outerProperty == 3         // #3
                  //assert getOuterProperty() == 4  // #4
              }
          }
          void test() {
              new Inner().assertions()
          }
      }
      new Outer().test()
      
      

      Assertion #2 fails at runtime with:

      Cannot find matching method Outer$Inner#getOuterProperty()

      which makes me think that the type checker does know that the method belongs to the outer class, but the receiver is not loaded properly. In fact, it should use a generated bridge method for the private method here.

      Uncommenting #4 leads to a static type checking error, which indicates that the getXXX method call is not checking that a property can be defined in an outer class.

      Attachments

        Activity

          People

            melix Cédric Champeau
            melix Cédric Champeau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: