[
https://issues.apache.org/jira/browse/GROOVY-12610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140534#comment-18140534
]
ASF GitHub Bot commented on GROOVY-12610:
-----------------------------------------
codeconsole commented on PR #3137:
URL: https://github.com/apache/groovy/pull/3137#issuecomment-6717091856
@daniellansun On the direction with #3169: @paulk-asert's preference there
is path (1) for 6.0.x regardless. That is this PR: keep the run-time behaviour
and have type checking report the access instead of letting it fail at run
time. For Groovy 7 it depends on GEP-31, with path (2) only if GEP-31 won't
land in time. So I'd land this PR, then #3147 (stacked on it), on master for
cherry-picking to GROOVY_6_0_X, and narrow or drop the rule on master if (2) is
taken for 7, as Paul describes, unless Paul would rather they target
GROOVY_6_0_X directly.
> 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
> Priority: Major
>
> {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)