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/09/10 22:45:09 UTC

[groovy] branch GROOVY_3_0_X updated (9629c8466b -> ecc279debc)

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 9629c8466b GROOVY-10291, GROOVY-10367: STC: diamond inference for object expression
     new 81bc2c9baa GROOVY-10254: STC: support SAM-type closure coerce on return
     new ecc279debc GROOVY-10256: STC: "Type x = m()" given "def <T extends NotType> T m();"

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:
 .../transform/stc/StaticTypeCheckingSupport.java   |  8 ++++--
 .../groovy/transform/stc/ClosuresSTCTest.groovy    | 31 ++++++++++++++++++++++
 .../groovy/transform/stc/GenericsSTCTest.groovy    |  4 +--
 3 files changed, 39 insertions(+), 4 deletions(-)


[groovy] 02/02: GROOVY-10256: STC: "Type x = m()" given "def T m();"

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 ecc279debc985c50166d2f7edd298ca642610997
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Sep 10 17:17:19 2022 -0500

    GROOVY-10256: STC: "Type x = m()" given "def <T extends NotType> T m();"
---
 .../org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java  | 4 ++--
 src/test/groovy/transform/stc/GenericsSTCTest.groovy                  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 55848f4403..c8cdebe597 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -731,8 +731,8 @@ public abstract class StaticTypeCheckingSupport {
             }
         }
 
-        // GROOVY-7316: It is an apparently legal thing to allow this. It's not type safe, but it is allowed...
-        return right.isGenericsPlaceHolder();
+        // GROOVY-7316, GROOVY-10256: "Type x = m()" given "def <T> T m()"; T adapts to target
+        return right.isGenericsPlaceHolder() && right.asGenericsType().isCompatibleWith(left);
     }
 
     private static boolean isGroovyConstructorCompatible(final Expression rightExpression) {
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index d0e91fd8d4..a750099d26 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -498,7 +498,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
         '''
     }
 
-    @NotYetImplemented // GROOVY-7316, GROOVY-10256
+    // GROOVY-7316, GROOVY-10256
     void testReturnTypeInferenceWithMethodGenerics16() {
         shouldFailWithMessages '''
             def <T extends CharSequence> T chars() {
@@ -507,7 +507,7 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
                 chars()
             }
         ''',
-        'Cannot return value of type #T for method returning java.util.List'
+        'Cannot return value of type T on method returning type java.util.List'
     }
 
     // GROOVY-10098


[groovy] 01/02: GROOVY-10254: STC: support SAM-type closure coerce on return

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 81bc2c9baaee2d69908c7de033b1ee6ad94dacff
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Sep 26 16:48:19 2021 -0500

    GROOVY-10254: STC: support SAM-type closure coerce on return
---
 .../transform/stc/StaticTypeCheckingSupport.java   |  4 +++
 .../groovy/transform/stc/ClosuresSTCTest.groovy    | 31 ++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
index 9611851b68..55848f4403 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -718,6 +718,10 @@ public abstract class StaticTypeCheckingSupport {
             return true;
         }
 
+        if (right.isDerivedFrom(CLOSURE_TYPE) && isSAMType(left)) {
+            return true;
+        }
+
         if (left.isGenericsPlaceHolder()) {
             // GROOVY-7307
             GenericsType[] genericsTypes = left.getGenericsTypes();
diff --git a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
index a910068280..0cdefd461b 100644
--- a/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosuresSTCTest.groovy
@@ -600,6 +600,24 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
         """
     }
 
+    // GROOVY-7003
+    void testSAMProperty2() {
+        assertScript '''
+            import java.beans.*
+
+            class C {
+                static PropertyChangeListener listener = { PropertyChangeEvent event ->
+                    result = "${event.oldValue} -> ${event.newValue}"
+                }
+                public static result
+            }
+
+            def event = new PropertyChangeEvent(new Object(), 'foo', 'bar', 'baz')
+            C.getListener().propertyChange(event)
+            assert C.result == 'bar -> baz'
+        '''
+    }
+
     void testSAMAttribute() {
         assertScript """
             interface SAM { def foo(); }
@@ -615,6 +633,19 @@ class ClosuresSTCTest extends StaticTypeCheckingTestCase {
         """
     }
 
+    // GROOVY-10254
+    void testSAMReturnType() {
+        assertScript '''
+            interface SAM<T> { T get() }
+            SAM<Integer> foo() {
+                return { -> 42 }
+            }
+
+            def result = foo().get()
+            assert result == 42
+        '''
+    }
+
     void testMultipleSAMSignature() {
         assertScript '''
             interface SAM { def foo() }