Skip to content
Permalink
Browse files
GROOVY-10556: "T" vs "C<T extends C<?>>" as bound of wildcard
  • Loading branch information
eric-milles committed Mar 30, 2022
1 parent 14b1aa7 commit 95c50ef12c3abe556205452ca18aaa954da486dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
@@ -278,13 +278,13 @@ private boolean checkGenerics(final ClassNode classNode) {
* @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
@@ -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 '''

0 comments on commit 95c50ef

Please sign in to comment.