GROOVY-12290: Private field access from another class compiles under … - #2828
GROOVY-12290: Private field access from another class compiles under …#2828paulk-asert wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses GROOVY-12290 by tightening static type checking so that plain property syntax can no longer “escape” into private-field access across foreign nests (cases that @CompileStatic cannot legally emit bytecode for), aligning behavior and error reporting between @TypeChecked and @CompileStatic. It also updates/relocates related regression tests and error-message expectations to reflect that the type checker now reports these failures earlier (instead of the static writer reporting them late).
Changes:
- Adjusts
StaticTypeCheckingVisitorso an inaccessible field can’t make a property writable, and blocks receiver-type “private access leniency” for property syntax across foreign nests (while keeping the intended dynamic escape hatches). - Adds new STC regression tests for foreign-nest private field access via property syntax vs attribute/delegate access, plus a nestmate bridge case.
- Updates existing constructor and bug regression tests to expect the new (earlier) type-checker error messages and removes a now-redundant override in the static-compile constructor test suite.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | Implements the foreign-nest private-field restriction for property syntax and adjusts readonly-property detection; adds record-component getter fallback. |
| src/test/groovy/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy | Adds GROOVY-12290 regression coverage for property vs attribute/delegate access and nestmate access bridging. |
| src/test/groovy/groovy/transform/stc/ConstructorsSTCTest.groovy | Updates constructor regression to expect “read-only property” failure from the type checker. |
| src/test/groovy/org/codehaus/groovy/classgen/asm/sc/StaticCompileConstructorsTest.groovy | Removes redundant override; relies on inherited test now that TC/CS error reporting matches. |
| src/test/groovy/bugs/Groovy7165.groovy | Updates expected error message now that the type checker reports the failure earlier. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2828 +/- ##
==================================================
+ Coverage 70.2594% 70.2595% +0.0001%
- Complexity 36274 36284 +10
==================================================
Files 1569 1569
Lines 133723 133737 +14
Branches 24637 24645 +8
==================================================
+ Hits 93953 93963 +10
- Misses 31257 31259 +2
- Partials 8513 8515 +2
🚀 New features to boost your workflow:
|
…TypeChecked but fails under @CompileStatic
6ffd88c to
c9a3460
Compare
✅ All tests passed ✅🏷️ Commit: c9a3460 Learn more about TestLens at testlens.app/docs. |
…@TypeChecked but fails under @CompileStatic