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

Compilation error when accessing a protected super class field from a closure using owner, delegate or thisObject qualifier (different package)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.8, 3.0.0-rc-1
    • 3.0.0-rc-2, 2.5.13
    • Static compilation
    • None

    Description

      Compilation fails when accessing a protected(via `thisObject`, `owner` and `delegate`)/package-private super class field from inside a closure:

      new GroovyShell().with {
        evaluate '''
          package a
          
          abstract class Abstract {
              protected String protectedField = 'field'
          }
          assert true
          '''
      
        evaluate '''
          package b
          
          @groovy.transform.CompileStatic
          class Concrete extends a.Abstract {
              String doThing() {
                  'something'.with {
                      return owner.protectedField // `thisObject.protectedField`, `delegate.protectedField` fails too
                  }
              }
          }
          assert true
          '''
      
        evaluate 'assert new b.Concrete().doThing() == "field"'
      

      Attachments

        Issue Links

          Activity

            People

              daniel_sun Daniel Sun
              daniel_sun Daniel Sun
              Votes:
              0 Vote for this issue
              Watchers:
              2 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 - 2h
                  2h