You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/09/22 11:53:13 UTC
[groovy] 03/03: GROOVY-9463: STC: add error for unknown method
pointer (closes #1373)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 745f567bc1beea5b7cc14e43fe3de1b77f214d6b
Author: Eric Milles <er...@thomsonreuters.com>
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 c2be2f1..b4f40ff 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2416,6 +2416,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.'
+ }
}