This is an automated email from the ASF dual-hosted git repository. paulk pushed a commit to branch GROOVY_3_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 25878c0b98c44ced07064f7f8bebdfd92726e7f7 Author: Eric Milles <[email protected]> AuthorDate: Mon Sep 21 14:11:32 2020 -0500 GROOVY-9463: STC: add error for unknown method pointer (closes #1373) --- .../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 4 ++++ src/test/groovy/transform/stc/BugsSTCTest.groovy | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 108fba4..decf839 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -2409,6 +2409,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport { .reduce(WideningCategories::lowestUpperBound) .filter(returnType -> !returnType.equals(OBJECT_TYPE)) .ifPresent(returnType -> storeType(expression, wrapClosureType(returnType))); + } else if (!(expression instanceof MethodReferenceExpression)) { + ClassNode type = wrapTypeIfNecessary(getType(expression.getExpression())); + if (isClassClassNodeWrappingConcreteType(type)) type = type.getGenericsTypes()[0].getType(); + addStaticTypeError("Cannot find matching method " + type.getText() + "#" + nameText + ". Please check if the declared type is correct and if the method exists.", nameExpr); } } } diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy index a0f21f9..fda9633 100644 --- a/src/test/groovy/transform/stc/BugsSTCTest.groovy +++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy @@ -820,7 +820,7 @@ Printer ''' } - //GROOVY-8590 + // GROOVY-8590 void testNestedMethodCallInferredTypeInReturnStmt() { assertScript ''' class Source { @@ -833,4 +833,10 @@ Printer ''' } + // GROOVY-9463 + void testMethodPointerUnknownReference() { + shouldFailWithMessages ''' + def ptr = String.&toLowerCaseX + ''', 'Cannot find matching method java.lang.String#toLowerCaseX.' + } }
