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 19:16:11 UTC
[groovy] branch GROOVY_3_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_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 677340e492 GROOVY-10807: SC: method call type arguments and method reference target
677340e492 is described below
commit 677340e4925f1f809bbd4772add6e0adfea72807
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Nov 4 14:00:26 2022 -0500
GROOVY-10807: SC: method call type arguments and method reference target
---
.../transform/stc/StaticTypeCheckingVisitor.java | 3 +-
.../transform/stc/MethodReferenceTest.groovy | 83 ++++++++++++++++++++--
2 files changed, 81 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 5aeb113fa5..0f2c9ace48 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2942,7 +2942,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 006efbebaf..f72bfa1f73 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -19,6 +19,7 @@
package groovy.transform.stc
import groovy.test.GroovyTestCase
+import groovy.test.NotYetImplemented
import static groovy.test.GroovyAssert.isAtLeastJdk
@@ -545,7 +546,7 @@ final class MethodReferenceTest extends GroovyTestCase {
}
// class::staticMethod
- void testFunctionCS_RHS() {
+ void testFunctionCS4() {
assertScript '''
import java.util.function.Function
import java.util.stream.Collectors
@@ -554,7 +555,6 @@ final class MethodReferenceTest extends GroovyTestCase {
void p() {
Function<Integer, Integer> f = Math::abs
def result = [1, -2, 3].stream().map(f).collect(Collectors.toList())
-
assert [1, 2, 3] == result
}
@@ -563,7 +563,7 @@ final class MethodReferenceTest extends GroovyTestCase {
}
// class::staticMethod
- void testFunctionCS_RHS_NOTYPE() {
+ void testFunctionCS5() {
assertScript '''
import java.util.stream.Collectors
@@ -571,7 +571,6 @@ final class MethodReferenceTest extends GroovyTestCase {
void p() {
def f = Math::abs // No explicit type defined, so it is actually a method closure. We can make it smarter in a later version.
def result = [1, -2, 3].stream().map(f).collect(Collectors.toList())
-
assert [1, 2, 3] == result
}
@@ -579,6 +578,81 @@ final class MethodReferenceTest extends GroovyTestCase {
'''
}
+ // class::staticMethod -- GROOVY-9813
+ @NotYetImplemented
+ void testFunctionCS6() {
+ assertScript '''
+ @groovy.transform.CompileStatic
+ void p() {
+ java.util.function.Supplier<List> zero = Arrays::asList
+ def list = zero.get()
+ assert list.isEmpty()
+ }
+
+ p()
+ '''
+ assertScript '''
+ @groovy.transform.CompileStatic
+ void p() {
+ java.util.function.Function<Integer, List> one = Arrays::asList
+ def list = one.apply(1)
+ assert list.size() == 1
+ assert list[0] == 1
+ }
+
+ p()
+ '''
+ assertScript '''
+ @groovy.transform.CompileStatic
+ void p() {
+ java.util.function.BiFunction<Integer, Integer, List> two = Arrays::asList
+ def list = two.apply(2,3)
+ assert list.size() == 2
+ assert list[0] == 2
+ assert list[1] == 3
+ }
+
+ p()
+ '''
+ }
+
+ // class::staticMethod -- GROOVY-10807
+ void testFunctionCS7() {
+ assertScript '''
+ @groovy.transform.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']
+ '''
+ }
+
+ // class::staticMethod
+ @NotYetImplemented
+ void testFunctionCS8() {
+ assertScript '''
+ @groovy.transform.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']
+ '''
+ }
+
// instance::instanceMethod
void testBinaryOperatorII_RHS() {
assertScript '''
@@ -741,6 +815,7 @@ final class MethodReferenceTest extends GroovyTestCase {
'''
}
+ // class::unknown
void testMethodNotFound1() {
def err = shouldFail '''
@groovy.transform.CompileStatic