You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/08/23 06:40:36 UTC

[PR] GROOVY-12290: Private field access from another class compiles under … [groovy]

paulk-asert opened a new pull request, #2828:
URL: https://github.com/apache/groovy/pull/2828

   …@TypeChecked but fails under @CompileStatic


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12290: Private field access from another class compiles under … [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2828:
URL: https://github.com/apache/groovy/pull/2828#issuecomment-5384895658

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 6ffd88cdb7b59385405e933459b085a4889eac82
   ▶️ Tests:  111712 executed
   ⚪️ Checks: 31/31 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12290: Private field access from another class compiles under … [groovy]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2828:
URL: https://github.com/apache/groovy/pull/2828#issuecomment-5384795541

   ## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2828?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `93.75000%` with `1 line` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 70.2571%. Comparing base ([`01f91d4`](https://app.codecov.io/gh/apache/groovy/commit/01f91d475918156df6c290460c70e3c7dfbe1e36?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`6ffd88c`](https://app.codecov.io/gh/apache/groovy/commit/6ffd88cdb7b59385405e933459b085a4889eac82?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 3 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2828?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2828?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2Fstc%2FStaticTypeCheckingVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9zdGMvU3RhdGljVHlwZUNoZWNraW5nVmlzaXRvci5qYXZh) | 93.7500% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2828?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/groovy/pull/2828/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/2828?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2828        +/-   ##
   ==================================================
   - Coverage     70.2594%   70.2571%   -0.0024%     
   - Complexity      36274      36284        +10     
   ==================================================
     Files            1569       1569                
     Lines          133723     133736        +13     
     Branches        24637      24645         +8     
   ==================================================
   + Hits            93953      93959         +6     
   - Misses          31257      31262         +5     
   - Partials         8513       8515         +2     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2828?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...roovy/transform/stc/StaticTypeCheckingVisitor.java](https://app.codecov.io/gh/apache/groovy/pull/2828?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2Fstc%2FStaticTypeCheckingVisitor.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9zdGMvU3RhdGljVHlwZUNoZWNraW5nVmlzaXRvci5qYXZh) | `87.2251% <93.7500%> (+0.0412%)` | :arrow_up: |
   
   ... and [11 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2828/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12290: Private field access from another class compiles under … [groovy]

Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #2828:
URL: https://github.com/apache/groovy/pull/2828


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12290: Private field access from another class compiles under … [groovy]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #2828:
URL: https://github.com/apache/groovy/pull/2828#discussion_r3837894972


##########
src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java:
##########
@@ -2522,10 +2534,32 @@ private boolean isStaticInContext(final MethodNode method) {
         return method instanceof ExtensionMethodNode ? ((ExtensionMethodNode) method).isStaticExtension() : method.isStatic();
     }
 
-    private boolean storeField(final FieldNode field, final PropertyExpression expressionToStoreOn, final ClassNode receiver, final ClassCodeVisitorSupport visitor, final String delegationData, final boolean lhsOfAssignment) {
-        boolean superField = isSuperExpression(expressionToStoreOn.getObjectExpression());
-        boolean accessible = (!superField && receiver.equals(field.getDeclaringClass()) && !field.getDeclaringClass().isAbstract()) // GROOVY-7300, GROOVY-11358
+    /**
+     * Determines if the field can back the given property (or attribute)
+     * expression: accessible by Java rules, or admitted by the receiver-type
+     * leniency (GROOVY-7300, GROOVY-11358) that models dynamic Groovy's
+     * permissive private access. Since GROOVY-12290 that leniency no longer
+     * admits plain property syntax to a private field of a foreign nest — a
+     * direct field access that static compilation cannot honour (no access
+     * bridge exists). The deliberate dynamic escape hatches remain: attribute
+     * access (.@), and closure bodies (GROOVY-9195) — including delegate-resolved
+     * access — whose property dispatch stays dynamic-capable under static compilation.
+     */
+    private boolean isFieldAccessible(final FieldNode field, final ClassNode receiver, final PropertyExpression expression, final String delegationData) {
+        boolean superField = isSuperExpression(expression.getObjectExpression());
+        boolean exactReceiver = (!superField && receiver.equals(field.getDeclaringClass()) && !field.getDeclaringClass().isAbstract()); // GROOVY-7300, GROOVY-11358
+        if (exactReceiver && field.isPrivate() && delegationData == null
+                && typeCheckingContext.getEnclosingClosure() == null
+                && !(expression instanceof AttributeExpression)
+                && getNestHost(field.getDeclaringClass()) != getNestHost(typeCheckingContext.getEnclosingClassNode())) {

Review Comment:
   The foreign-nest check uses reference inequality (`!=`) on the `ClassNode` returned by `getNestHost(...)`. Elsewhere in this class nest-host comparisons use `.equals(...)`, and `ClassNode` instances representing the same type are not guaranteed to be the same object. Using `!=` can incorrectly treat same-nest accesses as “foreign nest”, changing accessibility/readonly behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12290: Private field access from another class compiles under … [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2828:
URL: https://github.com/apache/groovy/pull/2828#issuecomment-5385785355

   ## ✅ All tests passed ✅
   
   🏷️ Commit: c9a34600759e06b66b0483abae7b8f46d52a491e
   ▶️ Tests:  111712 executed
   ⚪️ Checks: 31/31 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org