Skip to content

Commit 85fc2db

Browse files
committed
GROOVY-8448
1 parent c729da1 commit 85fc2db

File tree

7 files changed

+2432
-1
lines changed

7 files changed

+2432
-1
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/InnerClassTests.java

+18
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,24 @@ public void testAnonymousInnerClass34() {
17861786
runConformTest(sources);
17871787
}
17881788

1789+
@Test // GROOVY-8488
1790+
public void testAnonymousInnerClass35() {
1791+
//@formatter:off
1792+
String[] sources = {
1793+
"Script.groovy",
1794+
"def x = 'local'\n" + // shared variable written as field in AIC
1795+
"new Runnable() {\n" +
1796+
" def getX() { 'getter' }\n" +
1797+
" @Override void run() {\n" +
1798+
" print x + ' then ' + this.x\n" +
1799+
" }\n" +
1800+
"}.run()\n",
1801+
};
1802+
//@formatter:on
1803+
1804+
runConformTest(sources, "local then getter");
1805+
}
1806+
17891807
@Test
17901808
public void testMixedModeInnerProperties_GRE597() {
17911809
//@formatter:off

base/org.codehaus.groovy25/src/org/codehaus/groovy/classgen/AsmClassGenerator.java

+6
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,12 @@ private void visitAttributeOrProperty(PropertyExpression expression, MethodCalle
10831083
field = classNode.getDeclaredField(name); // params are stored as fields
10841084
} else {
10851085
field = classNode.getDeclaredField(name);
1086+
// GRECLIPSE add -- GROOVY-8448: "this.name" from inner class
1087+
if (field != null && (field.getModifiers() & ACC_SYNTHETIC) != 0
1088+
&& field.getType().equals(ClassHelper.REFERENCE_TYPE) && !expression.isImplicitThis()) {
1089+
field = null;
1090+
}
1091+
// GRECLIPSE end
10861092
if (field == null && controller.isStaticContext()
10871093
&& expression instanceof AttributeExpression) {
10881094
field = classNode.getField(name); // GROOVY-6183: check supers

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/AsmClassGenerator.java

+6
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,12 @@ public void visitPropertyExpression(final PropertyExpression expression) {
11341134
if (expression.isImplicitThis()) fieldNode = classNode.getDeclaredField(name);
11351135
} else {
11361136
fieldNode = classNode.getDeclaredField(name);
1137+
// GRECLIPSE add -- GROOVY-8448: "this.name" from inner class
1138+
if (fieldNode != null && (fieldNode.getModifiers() & ACC_SYNTHETIC) != 0
1139+
&& fieldNode.getType().equals(ClassHelper.REFERENCE_TYPE) && !expression.isImplicitThis()) {
1140+
fieldNode = null;
1141+
}
1142+
// GRECLIPSE end
11371143
}
11381144
if (fieldNode == null && !isValidFieldNodeForByteCodeAccess(getField(classNode, name), classNode)) {
11391145
// GROOVY-9501, GROOVY-9569, GROOVY-9650, GROOVY-9655, GROOVY-9665, GROOVY-9683, GROOVY-9695

base/org.codehaus.groovy40/.checkstyle

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<file-match-pattern match-pattern="groovy/ast/expr/(Static)?MethodCallExpression.java" include-pattern="false" />
3737
<file-match-pattern match-pattern="groovy/ast/tools/(Expression|Generics)Utils.java" include-pattern="false" />
3838
<file-match-pattern match-pattern="groovy/classgen/(Annotation|Enum)Visitor.java" include-pattern="false" />
39+
<file-match-pattern match-pattern="groovy/classgen/AsmClassGenerator.java" include-pattern="false" />
3940
<file-match-pattern match-pattern="groovy/classgen/(Extended)?Verifier.java" include-pattern="false" />
4041
<file-match-pattern match-pattern="groovy/classgen/asm/WriterController.java" include-pattern="false" />
4142
<file-match-pattern match-pattern="groovy/classgen/asm/sc/StaticInvocationWriter.java" include-pattern="false" />

0 commit comments

Comments
 (0)