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)

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.8, 3.0.0-rc-1
    • Fix Version/s: 3.0.0-rc-2, 2.5.13
    • Component/s: Static compilation
    • Labels:
      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

            • Assignee:
              daniel_sun Daniel Sun
              Reporter:
              daniel_sun Daniel Sun

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2h
                2h

                  Issue deployment