Skip to content

Commit af29aed

Browse files
committed
GROOVY-11467: SC: super interface method reference from an abstract type
1 parent 4695a35 commit af29aed

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesMethodReferenceExpressionWriter.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.Iterator;
4646
import java.util.List;
4747
import java.util.Map;
48+
import java.util.Set;
4849

4950
import static java.util.Comparator.comparingInt;
5051
import static java.util.stream.Collectors.joining;
@@ -308,10 +309,14 @@ private MethodNode chooseMethodRefMethod(final List<MethodNode> methods, final E
308309

309310
private List<MethodNode> findVisibleMethods(final String name, final ClassNode type) {
310311
List<MethodNode> methods = type.getMethods(name);
311-
// GROOVY-10791: include interface default methods in search
312-
for (ClassNode cn : getInterfacesAndSuperInterfaces(type)) {
312+
// GROOVY-10791, GROOVY-11467: include non-static interface methods
313+
Set<ClassNode> implemented = getInterfacesAndSuperInterfaces(type);
314+
implemented.remove(type);
315+
for (ClassNode cn : implemented) {
313316
for (MethodNode mn : cn.getDeclaredMethods(name)) {
314-
if (mn.isDefault()) methods.add(mn);
317+
if (mn.isDefault() || (mn.isPublic() && !mn.isStatic() && type.isAbstract())) {
318+
methods.add(mn);
319+
}
315320
}
316321
}
317322
methods.addAll(findDGMMethodsForClassNode(controller.getSourceUnit().getClassLoader(), type, name));

src/test/groovy/transform/stc/MethodReferenceTest.groovy

+20
Original file line numberDiff line numberDiff line change
@@ -1531,4 +1531,24 @@ final class MethodReferenceTest {
15311531
assert result == 'something'
15321532
'''
15331533
}
1534+
1535+
@Test // GROOVY-11467
1536+
void testSuperInterfaceMethodReference() {
1537+
assertScript imports + '''
1538+
interface A { int m() }
1539+
interface B extends A { }
1540+
class C implements B { int m() { 42 } }
1541+
1542+
@CompileStatic
1543+
class D {
1544+
B b = new C()
1545+
void test() {
1546+
IntSupplier s = b::m
1547+
assert s.getAsInt() == 42
1548+
}
1549+
}
1550+
1551+
new D().test()
1552+
'''
1553+
}
15341554
}

0 commit comments

Comments
 (0)