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 abbc6331ee8..681cf9f41a4 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 @@ protected void visitMethodCallArguments(final ClassNode receiver, final Argument 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 @@ private void checkClosureWithDelegatesTo(final ClassNode receiver, final MethodN 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 @@ public void addError(final String msg, final ASTNode node) { 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 8c1bdc7b641..22539d12c91 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 x = null + BiFunction, Number, Function> y = null + BinaryOperator> z = null + // reduce number(s) to string-to-integer functions + x.>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