Quantcast

[jira] [Commented] (GROOVY-8127) Access to Trait$Trait$Helper#$self is forbidden

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[jira] [Commented] (GROOVY-8127) Access to Trait$Trait$Helper#$self is forbidden

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/GROOVY-8127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15972293#comment-15972293 ]

Paul King commented on GROOVY-8127:
-----------------------------------

Just some examples without the JUnit dependency.

The Access forbidden to {{$self}} case:
{code}
@groovy.transform.CompileStatic
trait FooTrait {
    public final Runnable foo = { println new Date() } as Runnable
    void doRun() { foo.run() }
}

class Foo implements FooTrait { }

new Foo().doRun()
{code}
The {{$self}} in static context case:
{code}
trait TestTrait {
    boolean flag = true
    public final Runnable foo = { println flag } as Runnable
}
{code}

> Access to Trait$Trait$Helper#$self is forbidden
> -----------------------------------------------
>
>                 Key: GROOVY-8127
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8127
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.10
>            Reporter: Fran├žois Guillot
>
> 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:
> {code}
> import groovy.transform.CompileStatic
> import org.junit.Rule
> import org.junit.rules.TestRule
> @CompileStatic
> trait FooTrait {
>     @Rule
>     public final TestRule foo = {} as TestRule
> }
> {code}
> 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
> {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
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
Loading...