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:11 UTC

[groovy] 03/04: GROOVY-10095, GROOVY-10158, GROOVY-10226, GROOVY-10358: 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 2e7b5a893ec93d3329fe548ecf53b66b444b6c88
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon Mar 14 06:10:24 2022 -0500

    GROOVY-10095, GROOVY-10158, GROOVY-10226, GROOVY-10358: add test cases
---
 .../transform/stc/TernaryOperatorSTCTest.groovy    | 63 ++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
index 1b009d5..27d16d5 100644
--- a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.transform.stc
 
+import groovy.test.NotYetImplemented
+
 /**
  * Unit tests for static type checking : ternary operator.
  */
@@ -153,6 +155,31 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10358
+    void testCommonInterface() {
+        assertScript '''
+            interface I {
+                int m(int i)
+            }
+            abstract class A implements I {
+            }
+            class B<T> extends A {
+                int m(int i) {
+                    i + 1
+                }
+            }
+            class C<T> extends A {
+                int m(int i) {
+                    i - 1
+                }
+            }
+
+            C<String> c = null; int i = 1
+            int x = (false ? c : new B<String>()).m(i) // Cannot find matching method A#m(int)
+            assert x == 2
+        '''
+    }
+
     // GROOVY-5523
     void testNull1() {
         assertScript '''
@@ -206,4 +233,40 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
             assert test() == 42
         '''
     }
+
+    @NotYetImplemented // GROOVY-10095
+    void testNull4() {
+        assertScript '''
+            float x = false ? 1.0 : null
+        '''
+    }
+
+    // GROOVY-10226
+    void testNull5() {
+        assertScript '''
+            class A<T> {
+            }
+            def <T extends A<String>> T test() {
+                final T x = null
+                true ? (T) null : x
+            }
+            assert test() == null
+        '''
+    }
+
+    // GROOVY-10158
+    void testNull6() {
+        assertScript '''
+            class A<T> {
+            }
+            class B<T extends A<String>> {
+                T m() {
+                    final T x = null
+                    final T y = null
+                    ( true ? x : y )
+                }
+            }
+            assert new B<A<String>>().m() == null
+        '''
+    }
 }