This is an automated email from the ASF dual-hosted git repository. emilles pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push: new 08841a119b GROOVY-11683: STC: method reference: no covariants or equivalents 08841a119b is described below commit 08841a119b527903663f4c6d6fca0fcb9801c63e Author: Eric Milles <eric.mil...@thomsonreuters.com> AuthorDate: Tue Jun 10 15:14:44 2025 -0500 GROOVY-11683: STC: method reference: no covariants or equivalents --- .../groovy/transform/stc/StaticTypeCheckingSupport.java | 5 +++++ .../groovy/transform/stc/StaticTypeCheckingVisitor.java | 4 ++-- .../groovy/transform/stc/MethodReferenceTest.groovy | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java index 7d8a8edca0..d39fed0d47 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java @@ -128,6 +128,7 @@ import static org.codehaus.groovy.ast.tools.WideningCategories.isFloatingCategor import static org.codehaus.groovy.ast.tools.WideningCategories.isLongCategory; import static org.codehaus.groovy.ast.tools.WideningCategories.lowestUpperBound; import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean; +import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asList; import static org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport.closeQuietly; import static org.codehaus.groovy.syntax.Types.BITWISE_AND; import static org.codehaus.groovy.syntax.Types.BITWISE_AND_EQUAL; @@ -1038,6 +1039,10 @@ public abstract class StaticTypeCheckingSupport { if (methods.size() > 1 && !methods.iterator().next().isConstructor()) methods = removeCovariantsAndInterfaceEquivalents(methods, duckType); + if (argumentTypes == null) { + return asList(methods); // GROOVY-11683: no covariants or equivalents + } + Set<MethodNode> bestMethods = new HashSet<>(); // choose best method(s) for each possible receiver for (ClassNode rcvr : duckType ? ((UnionTypeClassNode) receiver).getDelegates() : new ClassNode[]{receiver}) { bestMethods.addAll(chooseBestMethods(rcvr, methods, argumentTypes)); diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 6e28420b5b..2f2e7e185e 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -2756,7 +2756,7 @@ out: if ((samParameterTypes.length == 1 && isOrImplements(samParameterTypes[0 private List<MethodNode> filterMethodCandidates(final List<MethodNode> candidates, final Expression objectOrType, /*@Nullable*/ ClassNode[] signature) { List<MethodNode> result = filterMethodsByVisibility(candidates, typeCheckingContext.getEnclosingClassNode()); // assignment or parameter target type may help reduce the list - if (result.size() > 1 && signature != null) { + if (result.size() > 1) { ClassNode type = getType(objectOrType); if (!isClassClassNodeWrappingConcreteType(type)) { result = chooseBestMethod(type, result, signature); @@ -2767,7 +2767,7 @@ out: if ((samParameterTypes.length == 1 && isOrImplements(samParameterTypes[0 result = new ArrayList<>(result.size()); result.addAll(chooseBestMethod(type, staticAndNonStatic.get(Boolean.TRUE), signature)); if (result.isEmpty() && !staticAndNonStatic.get(Boolean.FALSE).isEmpty()) { // GROOVY-11009 - if (signature.length > 0) signature= Arrays.copyOfRange(signature, 1, signature.length); + if (asBoolean(signature)) signature= Arrays.copyOfRange(signature, 1, signature.length); result.addAll(chooseBestMethod(type, staticAndNonStatic.get(Boolean.FALSE), signature)); } } diff --git a/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy index 2446bd8093..a622e579aa 100644 --- a/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy +++ b/src/test/groovy/groovy/transform/stc/MethodReferenceTest.groovy @@ -347,6 +347,23 @@ final class MethodReferenceTest { ''' } + // GROOVY-11683 + @Test // class::instanceMethod + void testFunctionCI12() { + assertScript shell, ''' + import java.util.stream.Stream + + @CompileStatic + List<Integer> test(List<String> strings) { + Stream.of(strings).flatMap(List::stream).map(Integer::valueOf).toList() + } + + def numbers = test(['1','2','3']) + assert numbers.size() == 3 + assert numbers == [1,2,3] + ''' + } + // GROOVY-9974 @Test // class::instanceMethod void testPredicateCI1() {