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:34:24 UTC

[groovy] branch GROOVY_4_0_X 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 GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new 4d764f1771 GROOVY-10807: SC: method call type arguments and method reference target
4d764f1771 is described below

commit 4d764f1771615ee88bda7511f874e7ea55fabe2e
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 89b931de4d..6534213809 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2969,7 +2969,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