You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/10/25 14:32:49 UTC
[groovy] branch GROOVY_4_0_X updated: GROOVY-10791: SC: support `NotTheInterface::defaultMethod`
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 6462d241fc GROOVY-10791: SC: support `NotTheInterface::defaultMethod`
6462d241fc is described below
commit 6462d241fcd0050bb703720638caa2d485b30aa8
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Oct 25 08:55:16 2022 -0500
GROOVY-10791: SC: support `NotTheInterface::defaultMethod`
---
.../asm/sc/StaticTypesMethodReferenceExpressionWriter.java | 10 ++++++++--
src/test/groovy/transform/stc/MethodReferenceTest.groovy | 12 ++++++++++++
2 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
index 6a3ec1ffd4..f6319b81ac 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java
@@ -49,6 +49,7 @@ import java.util.stream.Collectors;
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;
@@ -354,9 +355,14 @@ public class StaticTypesMethodReferenceExpressionWriter extends MethodReferenceE
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) {
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index ef9688f559..4c4011ea24 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -246,6 +246,18 @@ final class MethodReferenceTest {
'''
}
+ @Test // class::instanceMethod -- GROOVY-10791
+ void testBiConsumerCI() {
+ assertScript shell, '''
+ @CompileStatic
+ def <T> void test(List<T> list, Consumer<? super T> todo) {
+ BiConsumer<List<T>, Consumer<? super T>> binder = List::forEach // default method of Iterator
+ binder.accept(list, todo)
+ }
+ test(['works']) { assert it == 'works' }
+ '''
+ }
+
@Test // class::instanceMethod
void testBinaryOperatorCI() {
assertScript shell, '''