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 2020/09/10 22:15:26 UTC

[groovy] branch GROOVY-9735 created (now e8882af)

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

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


      at e8882af  GROOVY-9735: connect placeholder from context with method generic params

This branch includes the following new commits:

     new e8882af  GROOVY-9735: connect placeholder from context with method generic params

The 1 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.



[groovy] 01/01: GROOVY-9735: connect placeholder from context with method generic params

Posted by em...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-9735
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e8882afd09b8863c1c1aae197205348aafcf64fa
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Sep 10 17:15:08 2020 -0500

    GROOVY-9735: connect placeholder from context with method generic params
    
      @groovy.transform.TypeChecked
      class C<T extends Number> {
        List<T> list
        def test() {
          m(list) { /*...*/ } // "it" should infer as T/Number
        }
        def <U> void m(Iterable<U> items,
            @ClosureParams(FirstParam.FirstGenericType) Closure block) {
        }
      }
---
 .../transform/stc/StaticTypeCheckingSupport.java   |  7 +++--
 .../transform/stc/StaticTypeCheckingVisitor.java   |  2 ++
 .../stc/ClosureParamTypeInferenceSTCTest.groovy    | 33 ++++++++++++++++++++--
 3 files changed, 37 insertions(+), 5 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 b569fc9..eaead92 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -105,7 +105,6 @@ import static org.codehaus.groovy.ast.ClassHelper.make;
 import static org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching;
 import static org.codehaus.groovy.ast.ClassHelper.short_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.void_WRAPPER_TYPE;
-import static org.codehaus.groovy.ast.tools.GenericsUtils.getSuperClass;
 import static org.codehaus.groovy.runtime.DefaultGroovyMethods.asBoolean;
 import static org.codehaus.groovy.syntax.Types.BITWISE_AND;
 import static org.codehaus.groovy.syntax.Types.BITWISE_AND_EQUAL;
@@ -1744,7 +1743,7 @@ public abstract class StaticTypeCheckingSupport {
 
         } else {
             // first find matching super class or interface
-            ClassNode superClass = getSuperClass(type, target);
+            ClassNode superClass = GenericsUtils.getSuperClass(type, target);
             if (superClass != null) {
                 extractGenericsConnections(connections, getCorrectedClassNode(type, superClass, true), target);
             } else {
@@ -2141,7 +2140,9 @@ public abstract class StaticTypeCheckingSupport {
         if (rnTypes != null && cnTypes == null) return true;
         if (cnTypes != null) {
             for (GenericsType genericsType : cnTypes) {
-                if (genericsType.isPlaceholder()) return true;
+                if (genericsType.isPlaceholder()) {
+                    return genericsType.getType().equals(OBJECT_TYPE);
+                }
                 if (genericsType.isWildcard()) {
                     ClassNode lowerBound = genericsType.getLowerBound();
                     ClassNode[] upperBounds = genericsType.getUpperBounds();
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 f977ce1..06bec52 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -5134,7 +5134,9 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
                     Map<GenericsTypeName, GenericsType> connections = new HashMap<>();
                     extractGenericsConnections(connections, argumentType, paramType);
                     extractGenericsConnectionsForSuperClassAndInterfaces(resolvedPlaceholders, connections);
+
                     applyGenericsConnections(connections, resolvedPlaceholders);
+                    applyGenericsConnections(placeholdersFromContext, resolvedPlaceholders);
                 }
             }
         }
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index d991a6f..87416a2 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -1378,8 +1378,6 @@ method()
 
     void testGroovy9570() {
         assertScript '''
-            interface Item {}
-
             class C<I extends Item> {
                 Queue<I> queue
 
@@ -1396,6 +1394,37 @@ method()
                 }
             }
 
+            interface Item {}
+
+            new C()
+        '''
+    }
+
+    void testGroovy9735() {
+        assertScript '''
+            import groovy.transform.stc.*
+
+            class C<I extends Item> {
+                Queue<I> queue
+
+                def c = { ->
+                    x(queue) { I item ->
+                        println item
+                    }
+                }
+
+                def m() {
+                    x(queue) { I item ->
+                        println item
+                    }
+                }
+
+                def <T> T x(Collection<T> y, @ClosureParams(FirstParam.FirstGenericType) Closure z) {
+                }
+            }
+
+            interface Item {}
+
             new C()
         '''
     }