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 2022/12/16 19:56:08 UTC
[groovy] branch master updated: GROOVY-10807: SC: method target refines expected argument type(s)
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
The following commit(s) were added to refs/heads/master by this push:
new 02816f2c93 GROOVY-10807: SC: method target refines expected argument type(s)
02816f2c93 is described below
commit 02816f2c93954684469a3b7f2ee9aafcdd582251
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Dec 16 13:48:52 2022 -0600
GROOVY-10807: SC: method target refines expected argument type(s)
---
.../groovy/transform/stc/StaticTypeCheckingVisitor.java | 13 +++++++------
src/test/groovy/transform/stc/MethodReferenceTest.groovy | 4 +---
2 files changed, 8 insertions(+), 9 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 c8d3599379..12859f329c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2470,13 +2470,14 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
});
expression.putNodeMetaData(MethodNode.class, candidates);
- // GROOVY-10734: Type::instanceMethod has implied first parameter type
ClassNode[] arguments = expression.getNodeMetaData(CLOSURE_ARGUMENTS);
- if (asBoolean(arguments) && !isStaticInContext(candidates.get(0))
- && expression.getExpression() instanceof ClassExpression
- && (receiverType.isDerivedFrom(arguments[0])
- || receiverType.implementsInterface(arguments[0]))) {
- arguments[0] = receiverType;
+ if (arguments != null && arguments.length > 0) {
+ ClassNode[] parameters = collateMethodReferenceParameterTypes(expression, candidates.get(0));
+ for (int i = 0; i < arguments.length; i += 1) {
+ ClassNode at = arguments[i], pt = parameters[Math.min(i, parameters.length - 1)];
+ if (!pt.equals(at) && (at.isInterface() ? pt.implementsInterface(at) : pt.isDerivedFrom(at)))
+ arguments[i] = parameters[i]; // GROOVY-10734, GROOVY-10807: method refines expected type
+ }
}
} else if (!(expression instanceof MethodReferenceExpression)
|| this.getClass() == StaticTypeCheckingVisitor.class) {
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index 789874962b..a915fbd182 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -18,7 +18,6 @@
*/
package groovy.transform.stc
-import groovy.test.NotYetImplemented
import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
@@ -805,8 +804,7 @@ final class MethodReferenceTest {
'''
}
- @NotYetImplemented
- @Test // class::staticMethod
+ @Test // class::staticMethod -- GROOVY-10807
void testFunctionCS8() {
assertScript shell, '''
@CompileStatic