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
commit 6c31727fb733758af2fc61d4b512be75c9370f39 Author: Eric Milles <eric.mil...@thomsonreuters.com> AuthorDate: Sat Oct 5 08:46:14 2024 -0500 GROOVY-11181: STC: include parameter type in error --- .../transform/stc/StaticTypeCheckingVisitor.java | 12 ++++------- .../transform/stc/MethodReferenceTest.groovy | 24 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 10 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 abbc6331ee..681cf9f41a 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -3069,7 +3069,7 @@ out: if ((samParameterTypes.length == 1 && isOrImplements(samParameterTypes[0 expression.putNodeMetaData(PARAMETER_TYPE, lambda.getNodeMetaData(PARAMETER_TYPE)); expression.putNodeMetaData(CLOSURE_ARGUMENTS, lambda.getNodeMetaData(CLOSURE_ARGUMENTS)); } else { - addError("The argument is a method reference, but the parameter type is not a functional interface", expression); + addStaticTypeError("Argument is a method reference, but parameter type '" + prettyPrintTypeName(targetType) + "' is not a functional interface", expression); } } } @@ -3500,7 +3500,7 @@ out: if ((samParameterTypes.length == 1 && isOrImplements(samParameterTypes[0 resolveGenericsFromTypeHint(receiver, arguments, mn, resolved); expression.putNodeMetaData(DELEGATION_METADATA, newDelegationMetadata(resolved[0], stInt)); } else { - addStaticTypeError("Incorrect type hint found in method " + (mn), type); + addStaticTypeError("Incorrect type hint found in method " + mn, type); } } } else { @@ -5925,12 +5925,8 @@ trying: for (ClassNode[] signature : signatures) { protected void addStaticTypeError(final String msg, final ASTNode node) { if (node.getColumnNumber() > 0 && node.getLineNumber() > 0) { addError(StaticTypesTransformation.STATIC_ERROR_PREFIX + msg, node); - } else { - if (DEBUG_GENERATED_CODE) { - addError(StaticTypesTransformation.STATIC_ERROR_PREFIX + "Error in generated code [" + node.getText() + "] - " + msg, node); - } - // ignore errors which are related to unknown source locations - // because they are likely related to generated code + } else if (DEBUG_GENERATED_CODE) { // if not debug, ignore errors which are related to unknown source locations (generated code) + addError(StaticTypesTransformation.STATIC_ERROR_PREFIX + "Error in generated code [" + node.getText() + "] - " + msg, node); } } diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy index 8c1bdc7b64..22539d12c9 100644 --- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy +++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy @@ -1456,7 +1456,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 @@ -1473,7 +1473,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 shell, ''' + 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