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/11/04 18:33:00 UTC
[groovy] branch master updated: GROOVY-10807: SC: method call type arguments and method reference target
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 7e3091985f GROOVY-10807: SC: method call type arguments and method reference target
7e3091985f is described below
commit 7e3091985f72c6dd1350259bdf189cc231c2a642
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Nov 4 13:01:28 2022 -0500
GROOVY-10807: SC: method call type arguments and method reference target
---
.../transform/stc/StaticTypeCheckingVisitor.java | 3 +-
.../transform/stc/MethodReferenceTest.groovy | 45 ++++++++++++++++++++--
2 files changed, 43 insertions(+), 5 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 37d7934f21..88610a43bd 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2987,7 +2987,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
Expression emc = typeCheckingContext.getEnclosingMethodCall();
if (emc instanceof MethodCallExpression) {
MethodCallExpression mce = (MethodCallExpression) emc;
- if (mce.getArguments() == arguments) {
+ if (mce.getArguments() == arguments // GROOVY-10807 ::
+ || expression.getCode() == GENERATED_EMPTY_STATEMENT){
GenericsType[] typeArguments = mce.getGenericsTypes();
if (typeArguments != null) {
int n = typeParameters.length;
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index 4c4011ea24..3ddd3c3892 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -783,7 +783,44 @@ final class MethodReferenceTest {
'''
}
- @Test // class::instanceMethod, actually class::staticMethod
+ @Test // class::staticMethod -- GROOVY-10807
+ void testFunctionCS7() {
+ assertScript shell, '''
+ @CompileStatic
+ class C {
+ public static Comparator<String> c = Comparator.<String,String>comparing(C::m)
+ static String m(String string) {
+ return string
+ }
+ }
+
+ List<String> list = ['foo','bar','baz']
+ list.sort(C.c)
+
+ assert list == ['bar','baz','foo']
+ '''
+ }
+
+ @groovy.test.NotYetImplemented
+ @Test // class::staticMethod
+ void testFunctionCS8() {
+ assertScript shell, '''
+ @CompileStatic
+ class C {
+ public static Comparator<String> c = Comparator.comparing(C::m)
+ static String m(String string) {
+ return string
+ }
+ }
+
+ List<String> list = ['foo','bar','baz']
+ list.sort(C.c)
+
+ assert list == ['bar','baz','foo']
+ '''
+ }
+
+ @Test // class::instanceGroovyMethod
void testFunctionCI_DGM() {
assertScript shell, '''
@CompileStatic
@@ -795,7 +832,7 @@ final class MethodReferenceTest {
'''
}
- @Test // class::staticMethod
+ @Test // class::staticGroovyMethod
void testFunctionCS_DGSM() {
assertScript shell, '''
@CompileStatic
@@ -807,7 +844,7 @@ final class MethodReferenceTest {
'''
}
- @Test // class::instanceMethod
+ @Test // class::instanceGroovyMethod
void testFunctionCI_SHADOW_DGM() {
assertScript shell, '''
@CompileStatic
@@ -820,7 +857,7 @@ final class MethodReferenceTest {
'''
}
- @Test // class::staticMethod
+ @Test // class::staticGroovyMethod
void testFunctionCS_MULTI_DGSM() {
assertScript shell, '''
@CompileStatic