[
https://issues.apache.org/jira/browse/GROOVY-12523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18132127#comment-18132127
]
ASF GitHub Bot commented on GROOVY-12523:
-----------------------------------------
testlens-app[bot] commented on PR #3050:
URL: https://github.com/apache/groovy/pull/3050#issuecomment-6408248501
## ✅ All tests passed ✅
🏷️ Commit: 2add90fb801c34fa282fe45cd61d9a24d989dfa1
▶️ Tests: 123053 executed
⚪️ Checks: 32/32 completed
---
_Learn more about TestLens at
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
> STC: x.@name is accepted for a private field of a superclass when the type of
> x is a subclass
> ---------------------------------------------------------------------------------------------
>
> Key: GROOVY-12523
> URL: https://issues.apache.org/jira/browse/GROOVY-12523
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> In a class nested in {{Outer}}, the type checker accepts {{sub.@f}}, where
> {{f}} is a private field of {{Outer}} and {{sub}} is typed as a subclass of
> {{Outer}}:
> {code:groovy}
> @groovy.transform.TypeChecked
> class Outer {
> private String f = 'outer'
> static class Sub extends Outer {
> String read(Sub sub) { sub.@f }
> }
> }
> new Outer.Sub().read(new Outer.Sub()) // MissingFieldException: No such
> field: f for class: Outer$Sub
> {code}
> Dynamic Groovy and {{@TypeChecked}} throw {{MissingFieldException}}, because
> the meta-class of a subclass offers no private field of its superclass.
> {{@CompileStatic}} reads the field. javac rejects {{sub.f}} ("f has private
> access in Outer"), since a private field is not a member of a subclass (JLS
> 8.2). With {{f}} declared in a nested class {{Box}} and {{Sub extends Box}},
> or with a top-level subclass, the type checker already rejects {{sub.@f}}
> with "Cannot access field". Seen in 5.0.8, 6.0.0 and master; 4.0.33 failed at
> run time in every mode.
> Expected: "Cannot access field: f of class: Outer", also for writes,
> closures, lambdas and {{new Sub().@f}}. {{this.@f}}, {{super.@f}}, {{((Outer)
> sub).@f}} and {{sub.@f}} inside {{Outer}} keep compiling.
> PR: https://github.com/apache/groovy/pull/3050
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)