Skip to content

Commit 972d34a

Browse files
committed
GROOVY-6954, GROOVY-11376
1 parent d2f77bc commit 972d34a

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java

+35
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,41 @@ public void testCompileStatic6904() {
13171317
runConformTest(sources, "works");
13181318
}
13191319

1320+
@Test
1321+
public void testCompileStatic6954() {
1322+
//@formatter:off
1323+
String[] sources = {
1324+
"Main.groovy",
1325+
"import groovy.transform.*\n" +
1326+
"@CompileStatic class C extends HashMap<String,String> {\n" +
1327+
" def a\n" +
1328+
" public b\n" +
1329+
" protected c\n" +
1330+
" @PackageScope d\n" +
1331+
" private e\n" +
1332+
" C() {\n" +
1333+
" this.a = 'a'\n" +
1334+
" this.b = 'b'\n" +
1335+
" this.c = 'c'\n" +
1336+
" this.d = 'd'\n" +
1337+
" this.e = 'e'\n" +
1338+
" print(this);\n" +
1339+
"def that = this;\n" +
1340+
" that.a = 'a'\n" + // not put
1341+
" that.b = 'b'\n" + // not put
1342+
" that.c = 'c'\n" + // not put
1343+
" that.d = 'd'\n" +
1344+
" that.e = 'e'\n" +
1345+
" print(that);\n" +
1346+
" }\n" +
1347+
"}\n" +
1348+
"new C()\n",
1349+
};
1350+
//@formatter:on
1351+
1352+
runConformTest(sources, "[:][d:d, e:e]");
1353+
}
1354+
13201355
@Test
13211356
public void testCompileStatic6921() {
13221357
//@formatter:off

base/org.codehaus.groovy30/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,10 @@ public void fallbackAttributeOrPropertySite(final PropertyExpression expression,
824824
}
825825
}
826826
}
827-
// GRECLIPSE add -- GROOVY-6954
828-
if (isOrImplements(receiverType, MAP_TYPE) && !isClassReceiver[0]) {
827+
// GRECLIPSE add -- GROOVY-6954, GROOVY-11376
828+
if (!isClassReceiver[0] && isOrImplements(receiverType, MAP_TYPE) &&
829+
!java.util.Optional.ofNullable(getField(receiverType, name))
830+
.filter(f -> f.isPublic() || f.isProtected()).isPresent()) {
829831
MethodVisitor mv = controller.getMethodVisitor();
830832

831833
// store value in temporary variable

base/org.codehaus.groovy40/src/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java

+6
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,13 @@ public void fallbackAttributeOrPropertySite(final PropertyExpression expression,
819819
}
820820
}
821821
}
822+
/* GRECLIPSE edit -- GROOVY-11376
822823
if (isOrImplements(receiverType, MAP_TYPE) && !isClassReceiver[0]) {
824+
*/
825+
if (!isClassReceiver[0] && isOrImplements(receiverType, MAP_TYPE) &&
826+
!java.util.Optional.ofNullable(getField(receiverType, name))
827+
.filter(f -> f.isPublic() || f.isProtected()).isPresent()) {
828+
// GRECLIPSE end
823829
MethodVisitor mv = controller.getMethodVisitor();
824830

825831
// store value in temporary variable

0 commit comments

Comments
 (0)