This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 2776818b9b GROOVY-11358: STC: cannot access private field of abstract
class outside
2776818b9b is described below
commit 2776818b9ba8b92432de941e0f7ca9a9768dde2d
Author: Eric Milles <[email protected]>
AuthorDate: Wed Apr 10 09:05:54 2024 -0500
GROOVY-11358: STC: cannot access private field of abstract class outside
---
.../transform/stc/StaticTypeCheckingVisitor.java | 2 +-
.../stc/FieldsAndPropertiesSTCTest.groovy | 27 ++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index fae4a23fe6..86576e537d 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1894,7 +1894,7 @@ out: if ((samParameterTypes.length == 1 &&
isOrImplements(samParameterTypes[0
if (visitor != null) visitor.visitField(field);
checkOrMarkPrivateAccess(expressionToStoreOn, field, lhsOfAssignment);
boolean superField =
isSuperExpression(expressionToStoreOn.getObjectExpression());
- boolean accessible = ( !superField &&
receiver.equals(field.getDeclaringClass()) ) // GROOVY-7300
+ boolean accessible = (!superField &&
receiver.equals(field.getDeclaringClass()) &&
!field.getDeclaringClass().isAbstract()) // GROOVY-7300, GROOVY-11358
||
hasAccessToMember(typeCheckingContext.getEnclosingClassNode(),
field.getDeclaringClass(), field.getModifiers());
if (!accessible) {
diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
index 39ffaa9f81..c3531e5135 100644
--- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
+++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy
@@ -1081,6 +1081,33 @@ class FieldsAndPropertiesSTCTest extends
StaticTypeCheckingTestCase {
}
}
+ // GROOVY-11358
+ void testPrivateFieldAccessOfAbstract() {
+ shouldFailWithMessages '''
+ abstract class A {
+ private int f
+ }
+ void test(A a) {
+ int i = a.@f // MissingFieldException
+ int j = a.f // MissingPropertyException
+ }
+ test(new A() {})
+ ''',
+ 'Cannot access field: f of class: A', 'No such property: f for class:
A'
+
+ shouldFailWithMessages '''
+ abstract class A {
+ private int f
+ }
+ void test(A a) {
+ a.@f = 1 // MissingFieldException
+ a.f = 2 // MissingPropertyException
+ }
+ test(new A() {})
+ ''',
+ 'Cannot access field: f of class: A', 'No such property: f for class:
A'
+ }
+
// GROOVY-5737
void testGeneratedFieldAccessInClosure() {
assertScript '''