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/05/16 15:44:43 UTC

[groovy] branch GROOVY_3_0_X updated (28ac92b666 -> 44801fbde2)

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

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


    from 28ac92b666 bump to latest branch
     new 1e3434dfe4 GROOVY-10230, GROOVY-10330: given type param `T`, LUB(`T`,`T`) is `T`
     new 44801fbde2 GROOVY-10363: STC: fix target type check for type parameter

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:
 .../groovy/ast/tools/WideningCategories.java       |  8 ++++--
 .../transform/stc/StaticTypeCheckingVisitor.java   |  4 +--
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  2 +-
 .../transform/stc/TernaryOperatorSTCTest.groovy    | 33 ++++++++++++++++++++++
 4 files changed, 41 insertions(+), 6 deletions(-)


[groovy] 01/02: GROOVY-10230, GROOVY-10330: given type param `T`, LUB(`T`,`T`) is `T`

Posted by em...@apache.org.
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

commit 1e3434dfe4c178eead4efb96bcfcb42019f9f59c
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Oct 30 10:51:57 2021 -0500

    GROOVY-10230, GROOVY-10330: given type param `T`, LUB(`T`,`T`) is `T`
---
 .../groovy/ast/tools/WideningCategories.java       |  8 +++++---
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  2 +-
 .../transform/stc/TernaryOperatorSTCTest.groovy    | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
index b82db7224e..64d9e7bf43 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java
@@ -206,10 +206,12 @@ public class WideningCategories {
      */
     public static ClassNode lowestUpperBound(ClassNode a, ClassNode b) {
         ClassNode lub = lowestUpperBound(a, b, null, null);
-        if (lub==null || !lub.isUsingGenerics()) return lub;
-        // types may be parameterized. If so, we must ensure that generic type arguments
+        if (lub == null || !lub.isUsingGenerics()
+                || lub.isGenericsPlaceHolder()) { // GROOVY-10330
+            return lub;
+        }
+        // types may be parameterized; if so, ensure that generic type arguments
         // are made compatible
-
         if (lub instanceof LowestUpperBoundClassNode) {
             // no parent super class representing both types could be found
             // or both class nodes implement common interfaces which may have
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index f09d895c25..2582791dfa 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -1164,7 +1164,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-    @NotYetImplemented // GROOVY-10230
+    // GROOVY-10230
     void testDiamondInferrenceFromConstructor23() {
         assertScript '''
             class A {
diff --git a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
index 612b4425d6..063e95a929 100644
--- a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
@@ -131,6 +131,28 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10330
+    void testTypeParameterTypeParameter() {
+        assertScript '''
+            class C<T> {
+                T y
+                void m(T x, java.util.function.Function<T, T> f) {
+                    assert f.apply(x) == 'foo'
+                }
+                void test(T x, java.util.function.Function<T, T> f) {
+                    @ASTTest(phase=INSTRUCTION_SELECTION, value={
+                        def type = node.getNodeMetaData(INFERRED_TYPE)
+                        assert type.isGenericsPlaceHolder()
+                        assert type.unresolvedName == 'T'
+                    })
+                    def z = true ? x : y
+                    m(z, f)
+                }
+            }
+            new C<String>().test('FOO', { it.toLowerCase() })
+        '''
+    }
+
     // GROOVY-10357
     void testAbstractMethodDefault() {
         assertScript '''


[groovy] 02/02: GROOVY-10363: STC: fix target type check for type parameter

Posted by em...@apache.org.
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

commit 44801fbde2d9cff8933cfd702b3b452b3a660a68
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Mon May 16 10:31:46 2022 -0500

    GROOVY-10363: STC: fix target type check for type parameter
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java     |  4 ++--
 src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 3 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 b62e9e2717..3631754ce6 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4265,8 +4265,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
 
         if (expr instanceof ConstructorCallExpression) {
             inferDiamondType((ConstructorCallExpression) expr, targetType);
-        } else if (!isPrimitiveType(getUnwrapper(targetType))
-                && !OBJECT_TYPE.equals(targetType) && missesGenericsTypes(sourceType)) {
+        } else if (!isPrimitiveType(getUnwrapper(targetType)) && !targetType.equals(OBJECT_TYPE)
+                && !sourceType.isGenericsPlaceHolder() && missesGenericsTypes(sourceType)) {
             // unchecked assignment with ternary/elvis, like "List<T> list = listOfT ?: []"
             // the inferred type is the RHS type "completed" with generics information from LHS
             return GenericsUtils.parameterizeType(targetType, sourceType.getPlainNodeReference());
diff --git a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
index 063e95a929..91c59fccc2 100644
--- a/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
+++ b/src/test/groovy/transform/stc/TernaryOperatorSTCTest.groovy
@@ -132,7 +132,7 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
     }
 
     // GROOVY-10330
-    void testTypeParameterTypeParameter() {
+    void testTypeParameterTypeParameter1() {
         assertScript '''
             class C<T> {
                 T y
@@ -153,6 +153,17 @@ class TernaryOperatorSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
+    // GROOVY-10363
+    void testTypeParameterTypeParameter2() {
+        assertScript '''
+            def <X extends java.util.function.Supplier<Number>> X m(X x, X y) {
+                X z = true ? x : y // z infers as Supplier<Object>
+                return z
+            }
+            assert m(null,null) == null
+        '''
+    }
+
     // GROOVY-10357
     void testAbstractMethodDefault() {
         assertScript '''