Skip to content

Commit 8519e29

Browse files
committed
GROOVY-10379
1 parent bc05754 commit 8519e29

File tree

4 files changed

+194
-1
lines changed

4 files changed

+194
-1
lines changed

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

+175
Original file line numberDiff line numberDiff line change
@@ -2603,6 +2603,40 @@ public void testCompileStatic8686b() {
26032603
"----------\n");
26042604
}
26052605

2606+
@Test(expected = AssertionError.class)
2607+
public void testCompileStatic8693() {
2608+
//@formatter:off
2609+
String[] sources = {
2610+
"Main.groovy",
2611+
"@groovy.transform.CompileStatic\n" +
2612+
"class C extends p.A {\n" +
2613+
" void m() {\n" +
2614+
" super.m()\n" + // Cannot find matching method p.A#m()
2615+
" }\n" +
2616+
" void test() {\n" +
2617+
" m()\n" +
2618+
" }\n" +
2619+
"}\n" +
2620+
"new C().test()\n",
2621+
2622+
"p/A.java",
2623+
"package p;\n" +
2624+
"public abstract class A {\n" +
2625+
"}\n",
2626+
2627+
"p/I.java",
2628+
"package p;\n" +
2629+
"public interface I {\n" +
2630+
" default void m() {\n" +
2631+
" System.out.print(\"works\");\n" +
2632+
" }\n" +
2633+
"}\n",
2634+
};
2635+
//@formatter:on
2636+
2637+
runConformTest(sources, "works");
2638+
}
2639+
26062640
@Test
26072641
public void testCompileStatic8816() {
26082642
//@formatter:off
@@ -6236,6 +6270,44 @@ public void testCompileStatic9893a() {
62366270
runConformTest(sources, "String");
62376271
}
62386272

6273+
@Test(expected = AssertionError.class)
6274+
public void testCompileStatic9909() {
6275+
//@formatter:off
6276+
String[] sources = {
6277+
"Main.groovy",
6278+
"import p.*\n" +
6279+
"@groovy.transform.CompileStatic\n" +
6280+
"class C implements A, B {\n" +
6281+
" void m() {\n" +
6282+
" A.super.m()\n" +
6283+
" }\n" +
6284+
" void test() {\n" +
6285+
" m()\n" +
6286+
" }\n" +
6287+
"}\n" +
6288+
"new C().test()\n",
6289+
6290+
"p/A.java",
6291+
"package p;\n" +
6292+
"public interface A {\n" +
6293+
" default void m() {\n" +
6294+
" System.out.print(\"A\");\n" +
6295+
" }\n" +
6296+
"}\n",
6297+
6298+
"p/B.java",
6299+
"package p;\n" +
6300+
"public interface B {\n" +
6301+
" default void m() {\n" +
6302+
" System.out.print(\"B\");\n" +
6303+
" }\n" +
6304+
"}\n",
6305+
};
6306+
//@formatter:on
6307+
6308+
runConformTest(sources, "A");
6309+
}
6310+
62396311
@Test
62406312
public void testCompileStatic9918() {
62416313
//@formatter:off
@@ -6752,4 +6824,107 @@ public void testCompileStatic10377() {
67526824
checkDisassemblyFor("Main.class", "if_acmpne"); // ===
67536825
checkDisassemblyFor("Main.class", "if_acmpeq"); // !==
67546826
}
6827+
6828+
@Test
6829+
public void testCompileStatic10379() {
6830+
//@formatter:off
6831+
String[] sources = {
6832+
"Main.groovy",
6833+
"@groovy.transform.CompileStatic\n" +
6834+
"class C extends p.A {\n" +
6835+
" void test() {\n" +
6836+
" m('')\n" +
6837+
" }\n" +
6838+
"}\n" +
6839+
"new C().test()\n",
6840+
6841+
"p/A.groovy",
6842+
"package p\n" +
6843+
"abstract class A implements I {\n" +
6844+
" static void m(Number n) {\n" +
6845+
" print 'number'\n" +
6846+
" }\n" +
6847+
"}\n",
6848+
6849+
"p/I.java",
6850+
"package p;\n" +
6851+
"public interface I {\n" +
6852+
" default void m(String s) {\n" +
6853+
" System.out.print(\"string\");\n" +
6854+
" }\n" +
6855+
"}\n",
6856+
};
6857+
//@formatter:on
6858+
6859+
runConformTest(sources, "string");
6860+
}
6861+
6862+
@Test(expected = AssertionError.class)
6863+
public void testCompileStatic10380() {
6864+
//@formatter:off
6865+
String[] sources = {
6866+
"Main.groovy",
6867+
"@groovy.transform.CompileStatic\n" +
6868+
"class C extends p.A {\n" +
6869+
" void test() {\n" +
6870+
" m()\n" + // IncompatibleClassChangeError: Found class C, but interface was expected
6871+
" }\n" +
6872+
"}\n" +
6873+
"new C().test()\n",
6874+
6875+
"p/A.groovy",
6876+
"package p\n" +
6877+
"abstract class A implements I {\n" +
6878+
"}\n",
6879+
6880+
"p/I.java",
6881+
"package p;\n" +
6882+
"interface I {\n" +
6883+
" default void m() {\n" +
6884+
" System.out.print(\"works\");\n" +
6885+
" }\n" +
6886+
"}\n",
6887+
};
6888+
//@formatter:on
6889+
6890+
runConformTest(sources, "works");
6891+
}
6892+
6893+
@Test
6894+
public void testCompileStatic10381() {
6895+
//@formatter:off
6896+
String[] sources = {
6897+
"Main.groovy",
6898+
"@groovy.transform.CompileStatic\n" +
6899+
"class C implements p.A, p.B {\n" +
6900+
" void test() {\n" +
6901+
" m()\n" +
6902+
" }\n" +
6903+
"}\n" +
6904+
"new C().test()\n",
6905+
6906+
"p/A.java",
6907+
"package p;\n" +
6908+
"public interface A {\n" +
6909+
" default void m() {\n" +
6910+
" }\n" +
6911+
"}\n",
6912+
6913+
"p/B.java",
6914+
"package p;\n" +
6915+
"public interface B {\n" +
6916+
" default void m() {\n" +
6917+
" }\n" +
6918+
"}\n",
6919+
};
6920+
//@formatter:on
6921+
6922+
runNegativeTest(sources,
6923+
"----------\n" +
6924+
"1. ERROR in Main.groovy (at line 2)\n" +
6925+
"\tclass C implements p.A, p.B {\n" +
6926+
"\t ^\n" +
6927+
"Duplicate default methods named m with the parameters () and () are inherited from the types A and B\n" +
6928+
"----------\n");
6929+
}
67556930
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,15 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
13211321
return true;
13221322
}
13231323
}
1324+
// GRECLIPSE add -- GROOVY-10379
1325+
for (ClassNode in : cn.getAllInterfaces()) {
1326+
for (MethodNode mn : in.getDeclaredMethods(name)) {
1327+
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {
1328+
return true;
1329+
}
1330+
}
1331+
}
1332+
// GRECLIPSE end
13241333
}
13251334

13261335
return false;

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

+9
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,15 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
13121312
return true;
13131313
}
13141314
}
1315+
// GRECLIPSE add -- GROOVY-10379
1316+
for (ClassNode in : cn.getAllInterfaces()) {
1317+
for (MethodNode mn : in.getDeclaredMethods(name)) {
1318+
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {
1319+
return true;
1320+
}
1321+
}
1322+
}
1323+
// GRECLIPSE end
13151324
}
13161325

13171326
return false;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
13371337
return true;
13381338
}
13391339
}
1340-
// GRECLIPSE add -- GROOVY-9737
1340+
// GRECLIPSE add -- GROOVY-10379
13411341
for (ClassNode in : cn.getAllInterfaces()) {
13421342
for (MethodNode mn : in.getDeclaredMethods(name)) {
13431343
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {

0 commit comments

Comments
 (0)