Skip to content

Commit

Permalink
GROOVY-10791
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 25, 2022
1 parent 3f377f3 commit 8b55277
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7885,4 +7885,26 @@ public void testCompileStatic10742() {
"Groovy:Invalid return type: void is not convertible to java.lang.String\n" +
"----------\n");
}

@Test
public void testCompileStatic10791() {
assumeTrue(isParrotParser());

//@formatter:off
String[] sources = {
"Main.groovy",
"import java.util.function.*\n" +
"@SuppressWarnings('rawtypes')\n" +
"@groovy.transform.CompileStatic\n" +
"void test(List list) {\n" +
" BiConsumer<List,Consumer> bc = List::forEach\n" + // default method of Iterator
" Consumer printer = { print(it) }\n" +
" bc.accept(list, printer)\n" +
"}\n" +
"test(['works'])\n",
};
//@formatter:on

runConformTest(sources, "works");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.getInterfacesAndSuperInterfaces;
import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
import static org.codehaus.groovy.ast.tools.GenericsUtils.extractPlaceholders;
Expand Down Expand Up @@ -281,9 +282,14 @@ private MethodNode findMethodRefMethod(final String methodName, final Parameter[

private List<MethodNode> findVisibleMethods(final String name, final ClassNode type) {
List<MethodNode> methods = type.getMethods(name);
// GROOVY-10791: include interface default methods in search
for (ClassNode cn : getInterfacesAndSuperInterfaces(type)) {
for (MethodNode mn : cn.getDeclaredMethods(name)) {
if (mn.isDefault()) methods.add(mn);
}
}
methods.addAll(findDGMMethodsForClassNode(controller.getSourceUnit().getClassLoader(), type, name));
methods = filterMethodsByVisibility(methods, controller.getClassNode());
return methods;
return filterMethodsByVisibility(methods, controller.getClassNode());
}

private void addFatalError(final String msg, final ASTNode node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.classX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.ctorX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.getInterfacesAndSuperInterfaces;
import static org.codehaus.groovy.ast.tools.GeneralUtils.nullX;
import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS;
import static org.codehaus.groovy.ast.tools.GeneralUtils.varX;
Expand Down Expand Up @@ -354,9 +355,14 @@ else if (samParameters.length >= nParameters) { // 1+ case

private List<MethodNode> findVisibleMethods(final String name, final ClassNode type) {
List<MethodNode> methods = type.getMethods(name);
// GROOVY-10791: include interface default methods in search
for (ClassNode cn : getInterfacesAndSuperInterfaces(type)) {
for (MethodNode mn : cn.getDeclaredMethods(name)) {
if (mn.isDefault()) methods.add(mn);
}
}
methods.addAll(findDGMMethodsForClassNode(controller.getSourceUnit().getClassLoader(), type, name));
methods = filterMethodsByVisibility(methods, controller.getClassNode());
return methods;
return filterMethodsByVisibility(methods, controller.getClassNode());
}

private void addFatalError(final String msg, final ASTNode node) {
Expand Down

0 comments on commit 8b55277

Please sign in to comment.