[
https://issues.apache.org/jira/browse/GROOVY-12610?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18137324#comment-18137324
]
ASF GitHub Bot commented on GROOVY-12610:
-----------------------------------------
codeconsole commented on PR #3137:
URL: https://github.com/apache/groovy/pull/3137#issuecomment-6608403166
@paulk-asert I ran the shapes from #3137 and #3147 against #3169 (its three
changed files compiled over its base, eb37f3402a), dynamic and `@TypeChecked`.
These now return the value, in a static nested `Sub`: `z`, `this.z`,
`super.z`, closures, lambdas, `this.z = ..`, `z += ..`, `super.z = ..`, and
`that.z` with `Sub that`.
These still throw `MissingPropertyException`:
- `sub.z` from `Other`, another nested class of `Base`, and every case in
`testPrivateFieldOfSuperclassViaReceiverOfOtherClass`, where the receiver is
not an instance of the calling class. That is GROOVY-10198, by design.
- `super.z = ..`, `+=` and `++` in a non-static inner subclass.
`MetaClassImpl.isNestmateAccessor` excludes inner subclasses, and the
enclosing-instance fallback does not cover a write through `super`
(GROOVY-11823).
- `z`, `this.z`, `super.z` and writes in an enum constant body. `E$1` has
`ACC_ENUM | ACC_FINAL` but not `ACC_STATIC`, so `isNestmateAccessor` treats it
as having an enclosing instance. An anonymous subclass created in a static
method (flags 0, no `this$0`) takes the same path.
So under (2) the type checker still has to reject these: the #3137 rule
narrowed, not dropped. Separately, #3147 makes `E.this` in an enum constant
body a compile error instead of a `VerifyError`, whichever direction is taken.
Given your preference for (1) on 6.0.x, I'll keep #3137 and #3147 open.
Should they target `GROOVY_6_0_X`, or stay on master and be narrowed there if
(2) lands? I'll extend the rule to private methods in a follow-up.
> 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)