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 2024/10/05 14:42:41 UTC
(groovy) branch GROOVY_3_0_X updated: GROOVY-11181: STC: include parameter type in error
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 2827e14ea5 GROOVY-11181: STC: include parameter type in error
2827e14ea5 is described below
commit 2827e14ea53a5acf487d3ccc9c1183fc52a3ff82
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Oct 5 09:17:16 2024 -0500
GROOVY-11181: STC: include parameter type in error
3_0_X backport
---
.../transform/stc/StaticTypeCheckingVisitor.java | 8 ++++----
.../transform/stc/MethodReferenceTest.groovy | 24 ++++++++++++++++++++--
2 files changed, 26 insertions(+), 6 deletions(-)
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 3cd3859b0c..309bf3ff84 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3747,12 +3747,12 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (i >= nthParameter && paramType.isArray())
paramType = paramType.getComponentType();
- if (!isFunctionalInterface(paramType.redirect())) {
- addError("The argument is a method reference, but the parameter type is not a functional interface", argumentExpression);
- newArgumentExpressions.add(argumentExpression);
- } else {
+ if (isFunctionalInterface(paramType)) {
methodReferencePositions.add(i);
newArgumentExpressions.add(constructLambdaExpressionForMethodReference(paramType, (MethodReferenceExpression) argumentExpression));
+ } else {
+ newArgumentExpressions.add(argumentExpression);
+ addStaticTypeError("Argument is a method reference, but parameter type '" + prettyPrintTypeName(paramType) + "' is not a functional interface", argumentExpression);
}
}
}
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index b99bee8618..20bac107ec 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -1494,7 +1494,7 @@ final class MethodReferenceTest {
baz(this::foo) // not yet supported!
}
'''
- assert err =~ /The argument is a method reference, but the parameter type is not a functional interface/
+ assert err =~ /Argument is a method reference, but parameter type 'java.lang.Object' is not a functional interface/
}
@Test // GROOVY-10336
@@ -1511,7 +1511,27 @@ final class MethodReferenceTest {
}
}
'''
- assert err =~ /The argument is a method reference, but the parameter type is not a functional interface/
+ assert err =~ /Argument is a method reference, but parameter type 'java.lang.Object' is not a functional interface/
+ }
+
+ @Test // GROOVY-10979
+ void testNotFunctionalInterface3() {
+ def err = shouldFail imports + '''
+ Integer m(String x) {
+ return 1
+ }
+ @CompileStatic
+ void test() {
+ java.util.stream.Stream<Number> x = null
+ BiFunction<Function<String, Integer>, Number, Function<String, Integer>> y = null
+ BinaryOperator<Function<String, Integer>> z = null
+ // reduce number(s) to string-to-integer functions
+ x.<Function<String, Integer>>reduce(this::m, y, z)
+ x.reduce(this::m, y, z)
+ x.reduce((s) -> 1, y, z)
+ }
+ '''
+ assert err =~ /Argument is a method reference, but parameter type 'U' is not a functional interface/
}
@Test // GROOVY-11254