Skip to content

Commit 9647879

Browse files
committed
GROOVY-9737
1 parent 9a8c8d8 commit 9647879

4 files changed

Lines changed: 91 additions & 3 deletions

File tree

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5241,6 +5241,85 @@ public void testCompileStatic9734() {
52415241
runConformTest(sources, "");
52425242
}
52435243

5244+
@Test
5245+
public void testCompileStatic9737() {
5246+
//@formatter:off
5247+
String[] sources = {
5248+
"Main.groovy",
5249+
"@groovy.transform.CompileStatic\n" +
5250+
"class C extends p.A {\n" +
5251+
" void test() {\n" +
5252+
" m('')\n" + // VerifyError: Bad access to protected data in invokevirtual
5253+
" }\n" +
5254+
"}\n" +
5255+
"new C().test()\n",
5256+
5257+
"p/A.groovy",
5258+
"package p\n" +
5259+
"@groovy.transform.CompileStatic\n" +
5260+
"abstract class A {\n" +
5261+
" static void m(Integer i) { print 'int' }\n" +
5262+
" protected void m(String s) { print 'str' }\n" +
5263+
"}\n",
5264+
};
5265+
//@formatter:on
5266+
5267+
runConformTest(sources, "str");
5268+
}
5269+
5270+
@Test
5271+
public void testCompileStatic9737a() {
5272+
//@formatter:off
5273+
String[] sources = {
5274+
"Main.groovy",
5275+
"@groovy.transform.CompileStatic\n" +
5276+
"abstract class A {\n" +
5277+
" static void m(Integer i) { print 'int' }\n" +
5278+
" protected void m(String s) { print 'str' }\n" +
5279+
"}\n" +
5280+
"@groovy.transform.CompileStatic\n" +
5281+
"class C extends A {\n" +
5282+
" void test() {\n" +
5283+
" m('')\n" + // ClassCastException: class java.lang.Class cannot be cast to class A
5284+
" }\n" +
5285+
"}\n" +
5286+
"new C().test()\n",
5287+
};
5288+
//@formatter:on
5289+
5290+
runConformTest(sources, "str");
5291+
}
5292+
5293+
@Test @Ignore
5294+
public void testCompileStatic9737b() {
5295+
//@formatter:off
5296+
String[] sources = {
5297+
"Main.groovy",
5298+
"@groovy.transform.CompileStatic\n" +
5299+
"class C extends p.A {\n" +
5300+
" void test() {\n" +
5301+
" m('')\n" + // VerifyError: Bad access to protected data in invokevirtual
5302+
" }\n" +
5303+
"}\n" +
5304+
"new C().test()\n",
5305+
5306+
"p/A.groovy",
5307+
"package p\n" +
5308+
"abstract class A implements I {\n" +
5309+
" static void m(Integer i) { print 'int' }\n" +
5310+
"}\n",
5311+
5312+
"p/I.java",
5313+
"package p;\n" +
5314+
"interface I {\n" +
5315+
" default void m(String s) { System.out.print(\"str\"); }\n" +
5316+
"}\n",
5317+
};
5318+
//@formatter:on
5319+
5320+
runConformTest(sources, "str");
5321+
}
5322+
52445323
@Test
52455324
public void testCompileStatic9762() {
52465325
assumeTrue(isParrotParser());

base/org.codehaus.groovy25/src/org/codehaus/groovy/ast/ClassNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
13601360
}
13611361

13621362
for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
1363-
for (MethodNode mn : getDeclaredMethods(name)) {
1363+
for (MethodNode mn : cn.getDeclaredMethods(name)) { //GROOVY-9737
13641364
if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
13651365
return true;
13661366
}

base/org.codehaus.groovy30/src/org/codehaus/groovy/ast/ClassNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
13231323
}
13241324

13251325
for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
1326-
for (MethodNode mn : getDeclaredMethods(name)) {
1326+
for (MethodNode mn : cn.getDeclaredMethods(name)) { //GROOVY-9737
13271327
if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
13281328
return true;
13291329
}

base/org.codehaus.groovy40/src/org/codehaus/groovy/ast/ClassNode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,11 +1333,20 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
13331333
}
13341334

13351335
for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
1336-
for (MethodNode mn : getDeclaredMethods(name)) {
1336+
for (MethodNode mn : cn.getDeclaredMethods(name)) { //GROOVY-9737
13371337
if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
13381338
return true;
13391339
}
13401340
}
1341+
// GRECLIPSE add -- GROOVY-9737
1342+
for (ClassNode in : cn.getAllInterfaces()) {
1343+
for (MethodNode mn : in.getDeclaredMethods(name)) {
1344+
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {
1345+
return true;
1346+
}
1347+
}
1348+
}
1349+
// GRECLIPSE end
13411350
}
13421351

13431352
return false;

0 commit comments

Comments
 (0)