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

Access to Trait$Trait$Helper#$self is forbidden

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

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.10
    • 2.4.11
    • Compiler

    Description

      I'm switching from Groovy 2.4.7 to 2.4.10 in my project.

      I have a compile error with 2.4.10.
      Simplified example:

      import groovy.transform.CompileStatic
      import org.junit.Rule
      import org.junit.rules.TestRule
      @CompileStatic
      trait FooTrait {
          @Rule
          public final TestRule foo = {} as TestRule
      }
      

      I get "Error:Groovyc: Access to FooTrait$Trait$Helper#$self is forbidden"

      Another variant of this error is "Error:Groovyc: Apparent variable '$self'
      was found in a static scope but doesn't refer to a local variable, static
      field or class."

      This second error happens with the following code

      import groovy.transform.CompileStatic
      import org.junit.Rule
      import org.junit.rules.TestRule
      import org.junit.runner.Description
      import org.junit.runners.model.Statement
      
      @CompileStatic
      trait TestSupport {
      
          boolean failOnResourceLeak = true
      
          @Rule
          public final TestRule leakDetectionFlagRule = { Statement base, Description description ->
              return {
                  base.evaluate()
                  if (failOnResourceLeak) {
                      throw new Exception("A resource has leaked in this test!")
                  }
              } as Statement
          } as TestRule
      
      }
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            paulk Paul King
            facewindu François Guillot
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment