Skip to content

Commit

Permalink
GROOVY-11358
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Apr 10, 2024
1 parent edb36c0 commit 9c8fc21
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7703,4 +7703,35 @@ public void testTypeChecked11335() {

runConformTest(sources, "works");
}

@Test
public void testTypeChecked11358() {
//@formatter:off
String[] sources = {
"Main.groovy",
"abstract class A {\n" +
" private int f\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test(A a) {\n" +
" int i = a.@f\n" +
" int j = a.f\n" +
"}\n" +
"test(new A() {})\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 6)\n" +
"\tint i = a.@f\n" +
"\t ^\n" +
"Groovy:[Static type checking] - Cannot access field: f of class: A\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 7)\n" +
"\tint j = a.f\n" +
"\t ^^^\n" +
"Groovy:[Static type checking] - No such property: f for class: A\n" +
"----------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ private boolean isStaticInContext(final MethodNode method) {
private boolean storeField(final FieldNode field, final PropertyExpression expressionToStoreOn, final ClassNode receiver, final ClassCodeVisitorSupport visitor, final String delegationData, final boolean lhsOfAssignment) {
if (visitor != null) visitor.visitField(field);
checkOrMarkPrivateAccess(expressionToStoreOn, field, lhsOfAssignment);
/* GRECLIPSE edit -- GROOVY-11319
/* GRECLIPSE edit -- GROOVY-11319, GROOVY-11358
boolean accessible = hasAccessToMember(isSuperExpression(expressionToStoreOn.getObjectExpression()) ? typeCheckingContext.getEnclosingClassNode() : receiver, field.getDeclaringClass(), field.getModifiers());
if (expressionToStoreOn instanceof AttributeExpression) { // TODO: expand to include PropertyExpression
Expand All @@ -1930,7 +1930,7 @@ private boolean storeField(final FieldNode field, final PropertyExpression expre
}
*/
boolean superField = isSuperExpression(expressionToStoreOn.getObjectExpression());
boolean accessible = ( !superField && receiver.equals(field.getDeclaringClass()) ) // GROOVY-7300
boolean accessible = (!superField && receiver.equals(field.getDeclaringClass()) && !field.getDeclaringClass().isAbstract())
|| hasAccessToMember(typeCheckingContext.getEnclosingClassNode(), field.getDeclaringClass(), field.getModifiers());
if (!accessible) {
if (expressionToStoreOn instanceof AttributeExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ private boolean storeField(final FieldNode field, final PropertyExpression expre
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ private boolean storeField(final FieldNode field, final PropertyExpression expre
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) {
Expand Down

0 comments on commit 9c8fc21

Please sign in to comment.