Skip to content

Commit

Permalink
GROOVY-9737
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 25, 2021
1 parent 9a8c8d8 commit 9647879
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5241,6 +5241,85 @@ public void testCompileStatic9734() {
runConformTest(sources, "");
}

@Test
public void testCompileStatic9737() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C extends p.A {\n" +
" void test() {\n" +
" m('')\n" + // VerifyError: Bad access to protected data in invokevirtual
" }\n" +
"}\n" +
"new C().test()\n",

"p/A.groovy",
"package p\n" +
"@groovy.transform.CompileStatic\n" +
"abstract class A {\n" +
" static void m(Integer i) { print 'int' }\n" +
" protected void m(String s) { print 'str' }\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "str");
}

@Test
public void testCompileStatic9737a() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"abstract class A {\n" +
" static void m(Integer i) { print 'int' }\n" +
" protected void m(String s) { print 'str' }\n" +
"}\n" +
"@groovy.transform.CompileStatic\n" +
"class C extends A {\n" +
" void test() {\n" +
" m('')\n" + // ClassCastException: class java.lang.Class cannot be cast to class A
" }\n" +
"}\n" +
"new C().test()\n",
};
//@formatter:on

runConformTest(sources, "str");
}

@Test @Ignore
public void testCompileStatic9737b() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.CompileStatic\n" +
"class C extends p.A {\n" +
" void test() {\n" +
" m('')\n" + // VerifyError: Bad access to protected data in invokevirtual
" }\n" +
"}\n" +
"new C().test()\n",

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

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

runConformTest(sources, "str");
}

@Test
public void testCompileStatic9762() {
assumeTrue(isParrotParser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
}

for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
for (MethodNode mn : getDeclaredMethods(name)) {
for (MethodNode mn : cn.getDeclaredMethods(name)) { //GROOVY-9737
if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
}

for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
for (MethodNode mn : getDeclaredMethods(name)) {
for (MethodNode mn : cn.getDeclaredMethods(name)) { //GROOVY-9737
if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1333,11 +1333,20 @@ public boolean hasPossibleMethod(final String name, final Expression arguments)
}

for (ClassNode cn = this; cn != null; cn = cn.getSuperClass()) {
for (MethodNode mn : getDeclaredMethods(name)) {
for (MethodNode mn : cn.getDeclaredMethods(name)) { //GROOVY-9737
if (!mn.isStatic() && hasCompatibleNumberOfArgs(mn, count)) {
return true;
}
}
// GRECLIPSE add -- GROOVY-9737
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

0 comments on commit 9647879

Please sign in to comment.