You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/03/06 15:54:21 UTC

[groovy] branch master updated: GROOVY-9968: STC ClosureParams: for "T -> Type" use Type not Object

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

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d29445  GROOVY-9968: STC ClosureParams: for "T -> Type" use Type not Object
5d29445 is described below

commit 5d2944523f198d96b6515e85a24d2b4e43ce665f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Mar 5 14:54:44 2021 -0600

    GROOVY-9968: STC ClosureParams: for "T -> Type" use Type not Object
---
 .../groovy/transform/stc/StaticTypeCheckingVisitor.java |  2 +-
 .../stc/ClosureParamTypeInferenceSTCTest.groovy         | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

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 76247cc..252ffb8 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3120,7 +3120,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
         // TODO: Merge with StaticTypeCheckingSupport#getCombinedBoundType(GenericsType)?
         ClassNode value = genericsType.getType();
         if (genericsType.isPlaceholder()) {
-            value = OBJECT_TYPE;
+            value = value.isRedirectNode() ? value.redirect() : OBJECT_TYPE;
         }
         ClassNode lowerBound = genericsType.getLowerBound();
         if (lowerBound != null) {
diff --git a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
index 87416a2..bc0ac8a 100644
--- a/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
+++ b/src/test/groovy/transform/stc/ClosureParamTypeInferenceSTCTest.groovy
@@ -1480,4 +1480,21 @@ method()
             new B()
         '''
     }
+
+    void testGroovy9968() {
+        assertScript '''
+            import groovy.transform.*
+            @Canonical class Pogo { String prop }
+            @Canonical class Type<T extends Pogo> implements Iterable<T> {
+                Iterator<T> iterator() {
+                    list.iterator()
+                }
+                List<T> list
+            }
+
+            def iterable = new Type([new Pogo('x'), new Pogo('y'), new Pogo('z')])
+            assert iterable.collect { Pogo p -> p.prop } == ['x', 'y', 'z']
+            assert iterable.collect { it.prop } == ['x', 'y', 'z']
+        '''
+    }
 }