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 2021/03/07 03:11:55 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-9968: STC
ClosureParams: for "T -> Type" use Type not Object
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
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new 58bca3f GROOVY-9968: STC ClosureParams: for "T -> Type" use Type not Object
58bca3f is described below
commit 58bca3faa5fa8f8cdf0fe0affe090e7e82fba707
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 1bed8a0..37a224d 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3106,7 +3106,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
private static ClassNode createUsableClassNodeFromGenericsType(final GenericsType 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']
+ '''
+ }
}