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/03/14 16:51:10 UTC

[groovy] 02/04: GROOVY-10221, GROOVY-10356: add test cases

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

commit 082c90b0b45717a87b9cfa4eb617093268ff94f8
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Mar 14 06:18:05 2022 -0500

    GROOVY-10221, GROOVY-10356: add test cases
---
 .../groovy/transform/stc/ClosuresSTCTest.groovy    | 40 ++++++++++++++++++----
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index 02ea1b0..5988486 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.transform.stc
 
+import groovy.test.NotYetImplemented
+
 /**
  * Unit tests for static type checking : closures.
  */
@@ -373,9 +375,23 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
         'Cannot find matching method A#m()'
     }
 
-    // GROOVY-10052
+    @NotYetImplemented // GROOVY-10356
     void testClosureSharedVariable4() {
         assertScript '''
+            interface A {
+                void m()
+            }
+            def a = (A) null
+            def x = { ->
+                a = null
+            }
+            a?.m() // A closure shared variable [a] has been assigned with various types and ...
+        '''
+    }
+
+    // GROOVY-10052
+    void testClosureSharedVariable5() {
+        assertScript '''
             String x
             def f = { ->
                 x = Optional.of('x').orElseThrow{ new Exception() }
@@ -386,7 +402,7 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
     }
 
     // GROOVY-10052
-    void testClosureSharedVariable5() {
+    void testClosureSharedVariable6() {
         assertScript '''
             def x
             def f = { ->
@@ -524,12 +540,10 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
     // GROOVY-5693
     void testClosureArgumentCheckWithFlowTyping() {
         assertScript '''
-            Closure a = {
-                int i ->
+            Closure a = { int i ->
                 println "First closure "+ i
             }
-            Closure b = {
-                String s ->
+            Closure b = { String s ->
                 println "Second closure "+ s
             }
             a(5)
@@ -545,6 +559,20 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10221
+    void testClosureArgumentCheckWithFlowTyping2() {
+        assertScript '''
+            class C<T1, T2 extends T1> {
+                void test() {
+                    def one = { T2 x -> "" }
+                    Closure<T2> two = { T2 x -> x }
+                    one(two((T2) null))
+                }
+            }
+            new C<Number,Integer>().test()
+        '''
+    }
+
     // GROOVY-5705
     void testNPEWhenCallingClosureFromAField() {
         assertScript '''