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 2021/10/12 21:19:16 UTC

[groovy] branch GROOVY_3_0_X updated: GROOVY-10269: STC: no stack overflow when reference targets non-FI param

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 78c789c  GROOVY-10269: STC: no stack overflow when reference targets non-FI param
78c789c is described below

commit 78c789c46322a262fab583a2cb9d26504b5dc336
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Tue Oct 12 15:38:19 2021 -0500

    GROOVY-10269: STC: no stack overflow when reference targets non-FI param
    
    Conflicts:
    	src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
    	src/test/groovy/transform/stc/MethodReferenceTest.groovy
---
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 +
 .../transform/stc/MethodReferenceTest.groovy       | 65 ++++++++++++++++------
 2 files changed, 51 insertions(+), 16 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 4afb2ec..058440c 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3643,6 +3643,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
             methodReferenceParamIndexList.add(i);
         }
 
+        if (methodReferenceParamIndexList.isEmpty()) return; // GROOVY-10269
+
         visitMethodCallArguments(receiver, new ArgumentListExpression(newArgumentExpressionList), true, selectedMethod);
 
         for (Integer methodReferenceParamIndex : methodReferenceParamIndexList) {
diff --git a/src/test/groovy/transform/stc/MethodReferenceTest.groovy b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
index 4ff62ab..70ed133 100644
--- a/src/test/groovy/transform/stc/MethodReferenceTest.groovy
+++ b/src/test/groovy/transform/stc/MethodReferenceTest.groovy
@@ -20,7 +20,8 @@ package groovy.transform.stc
 
 import groovy.test.GroovyTestCase
 
-class MethodReferenceTest extends GroovyTestCase {
+final class MethodReferenceTest extends GroovyTestCase {
+
     // class::instanceMethod
     void testFunctionCI() {
         assertScript '''
@@ -565,22 +566,9 @@ class MethodReferenceTest extends GroovyTestCase {
         '''
     }
 
-    void testMethodNotFound() {
-        def errMsg = shouldFail '''
-            @groovy.transform.CompileStatic
-            void p() {
-                [1.0G, 2.0G, 3.0G].stream().reduce(0.0G, BigDecimal::addx)
-            }
-
-            p()
-        '''
-
-        assert errMsg.contains('Failed to find the expected method[addx(java.math.BigDecimal,java.math.BigDecimal)] in the type[java.math.BigDecimal]')
-    }
-
     // class::instanceMethod
     void testFunctionCI_WRONGTYPE() {
-        def errMsg = shouldFail '''
+        def err = shouldFail '''
             import java.util.stream.Collectors
 
             @groovy.transform.CompileStatic
@@ -593,7 +581,7 @@ class MethodReferenceTest extends GroovyTestCase {
             p()
         '''
 
-        assert errMsg.contains('Invalid receiver type: java.lang.Integer is not compatible with java.lang.String')
+        assert err =~ /Invalid receiver type: java.lang.Integer is not compatible with java.lang.String/
     }
 
     // class::instanceMethod, actually class::staticMethod
@@ -659,4 +647,49 @@ class MethodReferenceTest extends GroovyTestCase {
             p()
         '''
     }
+
+    void testMethodNotFound1() {
+        def err = shouldFail '''
+            @groovy.transform.CompileStatic
+            void p() {
+                [1.0G, 2.0G, 3.0G].stream().reduce(0.0G, BigDecimal::addx)
+            }
+        '''
+
+        assert err.contains('Failed to find the expected method[addx(java.math.BigDecimal,java.math.BigDecimal)] in the type[java.math.BigDecimal]')
+    }
+
+    // GROOVY-9463
+    void testMethodNotFound2() {
+        def err = shouldFail '''
+            import java.util.function.Function
+
+            @groovy.transform.CompileStatic
+            void p() {
+                Function<String,String> reference = String::toLowerCaseX
+            }
+        '''
+
+        assert err.contains('Failed to find the expected method[toLowerCaseX(java.lang.String)] in the type[java.lang.String]')
+    }
+
+    // GROOVY-10269
+    void testNotFunctionalInterface() {
+        def err = shouldFail '''
+            import java.util.function.Consumer
+
+            void foo(Integer y) {
+            }
+            void bar(Consumer<Integer> x) {
+            }
+            @groovy.transform.CompileStatic
+            void test() {
+                bar(this::foo)
+                def baz = { Consumer<Integer> x -> }
+                baz(this::foo) // not yet supported!
+            }
+        '''
+
+        assert err =~ /The argument is a method reference, but the parameter type is not a functional interface/
+    }
 }