You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2020/09/05 10:04:32 UTC
[groovy] 01/04: GROOVY-9460: fix matching for T>,
T super LB> and T extends UB>
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 558131384ff269310309e0426f12aad3228ec3b1
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Sep 4 14:13:13 2020 -0500
GROOVY-9460: fix matching for T<?>, T<? super LB> and T<? extends UB>
closes #1355
---
src/main/java/org/codehaus/groovy/ast/GenericsType.java | 14 ++++++--------
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 16 ++++++++++++++++
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 98f7b83..84f28f7 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -375,18 +375,16 @@ public class GenericsType extends ASTNode {
match = name.equals(gtn);
if (!match) {
GenericsType genericsType = boundPlaceHolders.get(gtn);
- match = false;
if (genericsType != null) {
if (genericsType.isPlaceholder()) {
match = true;
} else if (genericsType.isWildcard()) {
- if (genericsType.getUpperBounds() != null) {
- for (ClassNode ub : genericsType.getUpperBounds()) {
- match |= redirectBoundType.isCompatibleWith(ub);
- }
- if (genericsType.getLowerBound() != null) {
- match |= redirectBoundType.isCompatibleWith(genericsType.getLowerBound());
- }
+ if (genericsType.getUpperBounds() != null) { // multiple bounds not allowed for ?
+ match = redirectBoundType.isCompatibleWith(genericsType.getUpperBounds()[0]);
+ } else if (genericsType.getLowerBound() != null) {
+ match = redirectBoundType.isCompatibleWith(genericsType.getLowerBound());
+ } else {
+ match = true;
}
}
}
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index 3a434a3..896f3cc 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -393,6 +393,22 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-9460
+ void testMethodCallWithClassParameterUnbounded() {
+ assertScript '''
+ class Bar {
+ static void baz(Class<?> target) {
+ }
+ }
+ class Foo<D> { // cannot be "T" because that matches type parameter in Class
+ void test(Class<D> param) {
+ Bar.baz(param) // Cannot call Bar#baz(java.lang.Class<?>) with arguments [java.lang.Class<D>]
+ }
+ }
+ new Foo<String>().test(String.class)
+ '''
+ }
+
void testConstructorCallWithClassParameterUsingClassLiteralArg() {
assertScript '''
class A {}