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 2020/12/23 23:50:43 UTC
[groovy] branch master updated: GROOVY-9860: makeRawType should
reduce generic placeholder to bound type
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 8805d8e GROOVY-9860: makeRawType should reduce generic placeholder to bound type
8805d8e is described below
commit 8805d8e6e5b69a3d010a7d6647edfcb9ced3934f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 20 22:16:04 2020 -0600
GROOVY-9860: makeRawType should reduce generic placeholder to bound type
Tuple2 constructor parameters are placeholders and should reduce to
Object for argument matching
---
.../groovy/transform/stc/StaticTypeCheckingSupport.java | 2 +-
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
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 16008b7..2b404d8 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java
@@ -1127,7 +1127,7 @@ public abstract class StaticTypeCheckingSupport {
String name = param.getType().getUnresolvedName();
Optional<GenericsType> value = genericsPlaceholderAndTypeMap.entrySet().stream()
.filter(e -> e.getKey().getName().equals(name)).findFirst().map(Map.Entry::getValue);
- ClassNode type = value.map(GenericsType::getType).orElseGet(() -> makeRawType(param.getType()));
+ ClassNode type = value.map(gt -> !gt.isPlaceholder() ? gt.getType() : makeRawType(gt.getType())).orElseGet(() -> makeRawType(param.getType()));
return new Parameter(type, param.getName());
}).toArray(Parameter[]::new);
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 964e075..9f32908 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -427,6 +427,19 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-9860
+ void testGenericTypeArgumentInCtorCall() {
+ assertScript '''
+ def <T> void test() {
+ def bind = { T a, T b ->
+ new Tuple2<T, T>(a, b)
+ }
+ assert bind('foo', 'bar').toString() == '[foo, bar]'
+ }
+ test()
+ '''
+ }
+
void testReturnAnntationClass() {
assertScript '''
import java.lang.annotation.Documented