This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch GROOVY_3_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push: new af29aedf8f GROOVY-11467: SC: super interface method reference from an abstract type af29aedf8f is described below commit af29aedf8fe7c166b28a69dcb157a69c02a820de Author: Eric Milles <eric.mil...@thomsonreuters.com> AuthorDate: Wed Sep 4 09:14:56 2024 -0500 GROOVY-11467: SC: super interface method reference from an abstract type --- .../StaticTypesMethodReferenceExpressionWriter.java | 11 ++++++++--- .../groovy/transform/stc/MethodReferenceTest.groovy | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 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 2cb4b2a88e..122c4a7af1 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 @@ -45,6 +45,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import static java.util.Comparator.comparingInt; import static java.util.stream.Collectors.joining; @@ -308,10 +309,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)) { + // GROOVY-10791, GROOVY-11467: include non-static interface methods + Set<ClassNode> implemented = getInterfacesAndSuperInterfaces(type); + implemented.remove(type); + for (ClassNode cn : implemented) { for (MethodNode mn : cn.getDeclaredMethods(name)) { - if (mn.isDefault()) methods.add(mn); + if (mn.isDefault() || (mn.isPublic() && !mn.isStatic() && type.isAbstract())) { + methods.add(mn); + } } } methods.addAll(findDGMMethodsForClassNode(controller.getSourceUnit().getClassLoader(), type, name)); diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy index f9c8735187..b99bee8618 100644 --- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy +++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy @@ -1531,4 +1531,24 @@ final class MethodReferenceTest { assert result == 'something' ''' } + + @Test // GROOVY-11467 + void testSuperInterfaceMethodReference() { + assertScript imports + ''' + interface A { int m() } + interface B extends A { } + class C implements B { int m() { 42 } } + + @CompileStatic + class D { + B b = new C() + void test() { + IntSupplier s = b::m + assert s.getAsInt() == 42 + } + } + + new D().test() + ''' + } }