Skip to content

Commit

Permalink
GROOVY-10556
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Mar 30, 2022
1 parent c6bbb0e commit 301dacc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5560,4 +5560,24 @@ public void testTypeChecked10525() {

runConformTest(sources);
}

@Test
public void testTypeChecked10556() {
for (String self : new String[] {"(B) this", "this as B"}) {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TypeChecked\n" +
"abstract class A<B extends A<B,X>,X> {\n" +
" B m() {\n" +
" " + self + "\n" +
" }\n" +
"}\n" +
"(new A(){}).m()\n",
};
//@formatter:on

runConformTest(sources);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ private boolean checkGenerics(final ClassNode classNode) {
*/
private boolean compareGenericsWithBound(final ClassNode classNode, final ClassNode bound) {
if (classNode==null) return false;
// GRECLIPSE add -- GROOVY-10556: "T" vs "C<T extends C<?>>" bound
if (classNode.isGenericsPlaceHolder()) return true;
// GRECLIPSE end
if (bound.getGenericsTypes() == null || (classNode.getGenericsTypes()==null && classNode.redirect().getGenericsTypes()!=null)) {
// if the bound is not using generics, there's nothing to compare with
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,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
Expand Down

0 comments on commit 301dacc

Please sign in to comment.