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 2022/03/30 17:44:14 UTC
[groovy] 01/02: GROOVY-10556: "T" vs "C>" as bound of wildcard
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit 2a79294a0e8a0f5d50ad87b2c2449a7fe951ed12
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Mar 30 09:37:52 2022 -0500
GROOVY-10556: "T" vs "C<T extends C<?>>" as bound of wildcard
---
src/main/java/org/codehaus/groovy/ast/GenericsType.java | 12 ++++++------
src/test/groovy/transform/stc/GenericsSTCTest.groovy | 14 ++++++++++++++
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/ast/GenericsType.java b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
index 927c939..ab7dfbd 100644
--- a/src/main/java/org/codehaus/groovy/ast/GenericsType.java
+++ b/src/main/java/org/codehaus/groovy/ast/GenericsType.java
@@ -278,13 +278,13 @@ public class GenericsType extends ASTNode {
* @return true if generics are compatible
*/
private static boolean compareGenericsWithBound(final ClassNode classNode, final ClassNode bound) {
- if (classNode == null) {
- return false;
- }
- if (bound.getGenericsTypes() == null || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null)) {
- // if the bound is not using generics or the class node is a raw type, there's nothing to compare with
+ if (classNode == null) return false;
+ if (bound.getGenericsTypes() == null
+ || classNode.isGenericsPlaceHolder() // GROOVY-10556: "T" vs "C<T extends C<?>>" bound
+ || (classNode.getGenericsTypes() == null && classNode.redirect().getGenericsTypes() != null))
+ // if the bound is not using generics or the class node is a raw type, there's nothing to compare
return true;
- }
+
if (!classNode.equals(bound)) {
// the class nodes are on different types
// in this situation, we must choose the correct execution path : either the bound
diff --git a/src/test/groovy/transform/stc/GenericsSTCTest.groovy b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
index be1528d..c1a74d6 100644
--- a/src/test/groovy/transform/stc/GenericsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/GenericsSTCTest.groovy
@@ -4367,6 +4367,20 @@ class GenericsSTCTest extends StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10556
+ void testSelfReferentialTypeParameter3() {
+ ['(B) this', 'this as B'].each { self ->
+ assertScript """
+ abstract class A<B extends A<B,X>,X> {
+ B m() {
+ $self
+ }
+ }
+ (new A(){}).m()
+ """
+ }
+ }
+
// GROOVY-7804
void testParameterlessClosureToGenericSAMTypeArgumentCoercion() {
assertScript '''