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/30 17:44:13 UTC

[groovy] branch GROOVY_4_0_X updated (685c801 -> 09b1226)

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a change to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 685c801  GROOVY-10528: STC: fix NPE for raw type inference
     new 2a79294  GROOVY-10556: "T" vs "C<T extends C<?>>" as bound of wildcard
     new 09b1226  GROOVY-10557: add test case

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/codehaus/groovy/ast/GenericsType.java | 12 ++++-----
 .../groovy/transform/stc/GenericsSTCTest.groovy    | 31 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 6 deletions(-)

[groovy] 01/02: GROOVY-10556: "T" vs "C>" as bound of wildcard

Posted by em...@apache.org.
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 2a79294a0e8a0f5d50ad87b2c2449a7fe951ed12
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Mar 30 09:37:52 2022 -0500

    GROOVY-10556: "T" vs "C<T extends C<?>>" as bound of wildcard
---
 src/main/java/org/codehaus/groovy/ast/GenericsType.java | 12 ++++++------
 src/test/groovy/transform/stc/GenericsSTCTest.groovy    | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 927c939..ab7dfbd 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -278,13 +278,13 @@ public class GenericsType extends ASTNode {
      * @return true if generics are compatible
      */
     private static boolean compareGenericsWithBound(final ClassNode classNode, final ClassNode bound) {
-        if (classNode == null) {
-            return false;
-        }
-        if (bound.getGenericsTypes() == null || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null)) {
-            // if the bound is not using generics or the class node is a raw type, there's nothing to compare with
+        if (classNode == null) return false;
+        if (bound.getGenericsTypes() == null
+                || classNode.isGenericsPlaceHolder() // GROOVY-10556: "T" vs "C<T extends C<?>>" bound
+                || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null))
+            // if the bound is not using generics or the class node is a raw type, there's nothing to compare
             return true;
-        }
+
         if (!classNode.equals(bound)) {
              // the class nodes are on different types
             // in this situation, we must choose the correct execution path : either the bound
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index be1528d..c1a74d6 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -4367,6 +4367,20 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10556
+    void testSelfReferentialTypeParameter3() {
+        ['(B) this', 'this as B'].each { self ->
+            assertScript """
+                abstract class A<B extends A<B,X>,X> {
+                    B m() {
+                       $self
+                    }
+                }
+                (new A(){}).m()
+            """
+        }
+    }
+
     // GROOVY-7804
     void testParameterlessClosureToGenericSAMTypeArgumentCoercion() {
         assertScript '''

[groovy] 02/02: GROOVY-10557: add test case

Posted by em...@apache.org.
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 09b1226739a88347ac453488d939084d6fd4e58f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Mar 30 10:06:00 2022 -0500

    GROOVY-10557: add test case
---
 src/test/groovy/transform/stc/GenericsSTCTest.groovy | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index c1a74d6..c7bfe1b 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -3395,6 +3395,23 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10557
+    void testReturnTypeInferenceWithClosure2() {
+        assertScript '''
+            import java.util.function.Function
+            class C {
+                final <T> T m(Function<Reader,T> function)  {
+                    new StringReader("").withCloseable { reader ->
+                        function.apply(reader)
+                    }
+                }
+            }
+            Object result = new C().m { it.text.empty }
+            //                          ^^ StringReader
+            assert result == Boolean.TRUE
+        '''
+    }
+
     // GROOVY-6129
     void testShouldNotThrowNPE() {
         assertScript '''