Skip to content

Commit

Permalink
GROOVY-10379
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 25, 2021
1 parent bc05754 commit 8519e29
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2603,6 +2603,40 @@ public void testCompileStatic8686b() {
"----------\n");
}

@Test(expected = AssertionError.class)
public void testCompileStatic8693() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C extends p.A {\n" +
" void m() {\n" +
" super.m()\n" + // Cannot find matching method p.A#m()
" }\n" +
" void test() {\n" +
" m()\n" +
" }\n" +
"}\n" +
"new C().test()\n",

"p/A.java",
"package p;\n" +
"public abstract class A {\n" +
"}\n",

"p/I.java",
"package p;\n" +
"public interface I {\n" +
" default void m() {\n" +
" System.out.print(\"works\");\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "works");
}

@Test
public void testCompileStatic8816() {
//@formatter:off
Expand Down Expand Up @@ -6236,6 +6270,44 @@ public void testCompileStatic9893a() {
runConformTest(sources, "String");
}

@Test(expected = AssertionError.class)
public void testCompileStatic9909() {
//@formatter:off
String[] sources = {
"Main.groovy",
"import p.*\n" +
"@groovy.transform.CompileStatic\n" +
"class C implements A, B {\n" +
" void m() {\n" +
" A.super.m()\n" +
" }\n" +
" void test() {\n" +
" m()\n" +
" }\n" +
"}\n" +
"new C().test()\n",

"p/A.java",
"package p;\n" +
"public interface A {\n" +
" default void m() {\n" +
" System.out.print(\"A\");\n" +
" }\n" +
"}\n",

"p/B.java",
"package p;\n" +
"public interface B {\n" +
" default void m() {\n" +
" System.out.print(\"B\");\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "A");
}

@Test
public void testCompileStatic9918() {
//@formatter:off
Expand Down Expand Up @@ -6752,4 +6824,107 @@ public void testCompileStatic10377() {
checkDisassemblyFor("Main.class", "if_acmpne"); // ===
checkDisassemblyFor("Main.class", "if_acmpeq"); // !==
}

@Test
public void testCompileStatic10379() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C extends p.A {\n" +
" void test() {\n" +
" m('')\n" +
" }\n" +
"}\n" +
"new C().test()\n",

"p/A.groovy",
"package p\n" +
"abstract class A implements I {\n" +
" static void m(Number n) {\n" +
" print 'number'\n" +
" }\n" +
"}\n",

"p/I.java",
"package p;\n" +
"public interface I {\n" +
" default void m(String s) {\n" +
" System.out.print(\"string\");\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "string");
}

@Test(expected = AssertionError.class)
public void testCompileStatic10380() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C extends p.A {\n" +
" void test() {\n" +
" m()\n" + // IncompatibleClassChangeError: Found class C, but interface was expected
" }\n" +
"}\n" +
"new C().test()\n",

"p/A.groovy",
"package p\n" +
"abstract class A implements I {\n" +
"}\n",

"p/I.java",
"package p;\n" +
"interface I {\n" +
" default void m() {\n" +
" System.out.print(\"works\");\n" +
" }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "works");
}

@Test
public void testCompileStatic10381() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C implements p.A, p.B {\n" +
" void test() {\n" +
" m()\n" +
" }\n" +
"}\n" +
"new C().test()\n",

"p/A.java",
"package p;\n" +
"public interface A {\n" +
" default void m() {\n" +
" }\n" +
"}\n",

"p/B.java",
"package p;\n" +
"public interface B {\n" +
" default void m() {\n" +
" }\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 2)\n" +
"\tclass C implements p.A, p.B {\n" +
"\t ^\n" +
"Duplicate default methods named m with the parameters () and () are inherited from the types A and B\n" +
"----------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,15 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
return true;
}
}
// GRECLIPSE add -- GROOVY-10379
for (ClassNode in : cn.getAllInterfaces()) {
for (MethodNode mn : in.getDeclaredMethods(name)) {
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {
return true;
}
}
}
// GRECLIPSE end
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,15 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
return true;
}
}
// GRECLIPSE add -- GROOVY-10379
for (ClassNode in : cn.getAllInterfaces()) {
for (MethodNode mn : in.getDeclaredMethods(name)) {
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {
return true;
}
}
}
// GRECLIPSE end
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
return true;
}
}
// GRECLIPSE add -- GROOVY-9737
// GRECLIPSE add -- GROOVY-10379
for (ClassNode in : cn.getAllInterfaces()) {
for (MethodNode mn : in.getDeclaredMethods(name)) {
if (mn.isDefault() && hasCompatibleNumberOfArgs(mn, count)) {
Expand Down

0 comments on commit 8519e29

Please sign in to comment.