[
https://issues.apache.org/jira/browse/GROOVY-12509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149378#comment-18149378
]
ASF GitHub Bot commented on GROOVY-12509:
-----------------------------------------
codeconsole commented on PR #3050:
URL: https://github.com/apache/groovy/pull/3050#issuecomment-7084925451
Thank you. The branch is updated onto current master by a merge in 40c262d;
there were no conflicts. ffbb294 drops `@NotYetImplemented` from
`testGroovy12510`, `testGroovy12523` and `testGroovy12637`, with the assertions
unchanged. On the merged tree those three were the only `RegressionTest`
failures, and the whole class now passes. `testGroovy12511` and
`testGroovy12513` stay as they are. Both wording nits are fixed in 86afb3f: the
guide sentence now reads "Dynamic code finds a private field of `Base` through
`sub.name` only in `Base` or in an inner class whose enclosing instance is a
`Base`", ahead of the one on private static members, and the javadoc of
`StaticTypesMarker.ENCLOSING_INSTANCE_OF_RECEIVER` now describes any call or
operator whose method is one of an enclosing instance of the receiver, with the
receiver type as its value.
> STC: private members of another class of the same nest are not accessible
> -------------------------------------------------------------------------
>
> Key: GROOVY-12509
> URL: https://issues.apache.org/jira/browse/GROOVY-12509
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Assignee: Paul King
> Priority: Major
> Fix For: 7.0.0-alpha-1, 6.0.1
>
>
> Under static type checking, a class nested in a top-level class cannot use
> the private constructors, methods and accessors of another class nested in
> the same top-level class:
> {code:groovy}
> @groovy.transform.CompileStatic
> class C {
> static class Box {
> private Box(String s) {}
> private static String sm() { 'sm' }
> private String im() { 'im' }
> private String getX() { 'x' }
> }
> static class A { private static class Hidden { public static int x = 1 } }
> static class Other {
> static test(Box box) {
> new Box('a') // Cannot find matching constructor
> C$Box(java.lang.String)
> Box.sm() // Cannot find matching method java.lang.Class#sm()
> or static method C$Box#sm()
> box.im() // Cannot find matching method C$Box#im()
> box.x // No such property: x for class: C$Box
> A.Hidden.x // Cannot access field: x of class: C$A$Hidden from
> class: C$Other
> }
> }
> }
> {code}
> Java allows all of these (JLS 6.6.1: a private member is accessible anywhere
> within the body of the top-level class that encloses its declaration), and
> the JVM does through nestmates. Groovy already writes the {{NestHost}} and
> {{NestMembers}} attributes for these classes, the class generator already
> calls private members of nestmates directly, and the type checker already
> allows private fields of nestmates (GROOVY-12290). Method references such as
> {{Box::new}} and {{Box::sm}} are rejected the same way.
> The modes also disagree. With a private {{Box(String)}} beside a public
> {{Box(Object)}}, {{new Box('s')}} in {{Other}} calls the private constructor
> in dynamic and {{@TypeChecked}} code, as javac does, but the public one under
> {{@CompileStatic}}. The same happens for a private {{B.m(String)}} beside an
> inherited {{A.m(Object)}}.
> A private getter or setter used through property syntax ({{box.x}}) is also
> rejected from the outer class into a nested class.
> The last case, a public member reached through a private nested type
> ({{A.Hidden.x}}, or a constant of a private nested enum), worked in 5.0.8 and
> fails since 6.0.0 (GROOVY-12310), from a sibling and from the outer class.
> The other cases fail in 4.0, 5.0 and 6.0.
> PR: https://github.com/apache/groovy/pull/3044 (the private nested types; the
> other parts follow in separate pull requests)
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)