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

Daniel Sun commented on GROOVY-12610:
-------------------------------------

Fixed on master via #3137 (https://github.com/apache/groovy/pull/3137, 
eaf64f1a2bdbba7c61eb052de6fb391c4f08f5f9, 
https://github.com/apache/groovy/commit/eaf64f1a2bdbba7c61eb052de6fb391c4f08f5f9)
 and on the GROOVY_6_0_X branch in 528edf06fc8c86d88ea1e1bec1dc0c5399bec2a9 
(https://github.com/apache/groovy/commit/528edf06fc8c86d88ea1e1bec1dc0c5399bec2a9).
 The 6.0.x isStaticDispatchScope hook used by this change is in 
deb3d728bb4ed61b662c5b4c9562ec782becd845 
(https://github.com/apache/groovy/commit/deb3d728bb4ed61b662c5b4c9562ec782becd845).

> STC accepts access to a private superclass field through a nested subclass 
> under @TypeChecked, which fails at run time
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12610
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12610
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.33, 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Assignee: Daniel Sun
>            Priority: Major
>             Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> {code:groovy}
> class Base {
>     private String z = 'x'
>     @groovy.transform.TypeChecked
>     static class Sub extends Base {
>         def m() { this.z }   // also: z, super.z, closures, lambdas, writes, 
> that.z
>     }
> }
> new Base.Sub().m()
> {code}
> Actual: the code compiles, then fails with MissingPropertyException: No such 
> property: z for class: Base$Sub. Dynamic Groovy fails the same way.
> Expected: under @TypeChecked, a compile error "No such property: z for class: 
> Base$Sub", as already reported when Base and Sub are both nested in another 
> class. @CompileStatic keeps accepting the code, because it accesses the field 
> directly from a nest-mate.
> Cause: the type checker uses the nest-mate accessibility rule of static 
> compilation for @TypeChecked code too. Type-checked code is dispatched 
> dynamically, and the metaclass of a subclass does not list a private field of 
> its superclass.
> Seen in 4.0.33, 5.0.8 and 6.0.0.
> PR: https://github.com/apache/groovy/pull/3137



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to