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

Eric Milles edited comment on GROOVY-10059 at 4/27/21, 3:42 PM:
----------------------------------------------------------------

You can tag your class {{A}} or field {{foo}} with 
{{@groovy.transform.CompileStatic}} and the necessary bridge methods will get 
created so you can have this sort of construction.


was (Author: emilles):
You can tag your class {{A}} with {{@groovy.transform.CompileStatic}} and the 
necessary bridge methods will get created so you can have this sort of 
construction.

> Super Class Closure Can't Find Field when Any Method Overridden
> ---------------------------------------------------------------
>
>                 Key: GROOVY-10059
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10059
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.8, 4.0.0-alpha-3
>            Reporter: Ian
>            Priority: Major
>
> {noformat}
> class A {
>     private final boolean VAL = false
>     Closure foo = {
>         println VAL // Exception thrown from here
>     }
> }
> class B {
>     A a = new A() {} // Removing these braces makes it work as expected. Also 
> fails if an actual method is overridden here
>     def bar() {
>         a.foo()
>     }
> }
> new B().bar() // Running this throws exception
> //new A().foo() // Running this instead works as expected{noformat}
> Running this (script called OverrideFail.groovy) results in an exception:
> {noformat}
> Caught: groovy.lang.MissingPropertyException: No such property: VAL for 
> class: B
> Possible solutions: a
> groovy.lang.MissingPropertyException: No such property: VAL for class: B
> Possible solutions: a
>       at A$_closure1.doCall(OverrideFail.groovy:4)
>       at A$_closure1.doCall(OverrideFail.groovy)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at B.bar(OverrideFail.groovy:12)
>       at B$bar.call(Unknown Source)
>       at OverrideFail.run(OverrideFail.groovy:16)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to