Skip to content

Commit

Permalink
GROOVY-10125
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 7, 2021
1 parent 81aa7e3 commit bf6d32b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1120,13 +1120,32 @@ public void testCyclicReference5() {
"----------\n" +
"1. ERROR in C.groovy (at line 1)\n" +
"\tclass C<T extends T> {\n" +
"\t ^\n" +
"\t ^\n" +
"Groovy:Cycle detected: the type T cannot extend/implement itself or one of its own member types\n" +
"----------\n");
}

@Test
public void testCyclicReference6() {
//@formatter:off
String[] sources = {
"C.groovy",
"class C<T extends U, U extends T> {\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in C.groovy (at line 1)\n" +
"\tclass C<T extends U, U extends T> {\n" +
"\t ^\n" +
"Groovy:Cycle detected: the type T cannot extend/implement itself or one of its own member types\n" +
"----------\n");
}

@Test
public void testCyclicReference7() {
//@formatter:off
String[] sources = {
"C.groovy",
Expand All @@ -1145,7 +1164,7 @@ public void testCyclicReference6() {
}

@Test
public void testCyclicReference7() {
public void testCyclicReference8() {
//@formatter:off
String[] sources = {
"C.groovy",
Expand Down Expand Up @@ -1174,7 +1193,7 @@ public void testCyclicReference7() {
}

@Test
public void testCyclicReference8() {
public void testCyclicReference9() {
//@formatter:off
String[] sources = {
"I.groovy",
Expand Down Expand Up @@ -1203,7 +1222,7 @@ public void testCyclicReference8() {
}

@Test
public void testCyclicReference9() {
public void testCyclicReference10() {
//@formatter:off
String[] sources = {
"C.groovy",
Expand Down Expand Up @@ -1234,7 +1253,7 @@ public void testCyclicReference9() {
}

@Test // typo that caused overflow
public void testCyclicReference10() {
public void testCyclicReference11() {
//@formatter:off
String[] sources = {
"A.groovy",
Expand Down Expand Up @@ -1292,6 +1311,19 @@ public void testNonCyclicReference2() {
runNegativeTest(sources, "");
}

@Test // GROOVY-10125
public void testNonCyclicReference3() {
//@formatter:off
String[] sources = {
"C.groovy",
"class C<T, U extends T> {\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources, "");
}

@Test
public void testUnreachable_1047() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ public void visitClass(ClassNode node) {
for (ClassNode anInterface : node.getInterfaces()) {
resolveOrFail(anInterface, node, true);
}
/* GRECLIPSE edit -- GRECLIPSE-531, GROOVY-10113, et al.
/* GRECLIPSE edit -- GRECLIPSE-531, GROOVY-10113, GROOVY-10125, et al.
checkCyclicInheritance(node, node.getUnresolvedSuperClass(), node.getInterfaces());
*/
if (sn != null) checkCyclicInheritance(node, sn);
Expand All @@ -1601,7 +1601,7 @@ public void visitClass(ClassNode node) {
for (GenericsType gt : node.getGenericsTypes()) {
if (gt != null && gt.getUpperBounds() != null) {
for (ClassNode variant : gt.getUpperBounds()) {
if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(gt.getType().redirect(), variant);
if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(variant, gt.getType());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ public void visitClass(final ClassNode node) {
for (ClassNode anInterface : node.getInterfaces()) {
resolveOrFail(anInterface, "", node, true);
}
/* GRECLIPSE edit -- GROOVY-10113
/* GRECLIPSE edit -- GRECLIPSE-531, GROOVY-10113, GROOVY-10125, et al.
checkCyclicInheritance(node, node.getUnresolvedSuperClass(), node.getInterfaces());
*/
if (sn != null) checkCyclicInheritance(node, sn);
Expand All @@ -1491,7 +1491,7 @@ public void visitClass(final ClassNode node) {
for (GenericsType gt : node.getGenericsTypes()) {
if (gt != null && gt.getUpperBounds() != null) {
for (ClassNode variant : gt.getUpperBounds()) {
if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(gt.getType().redirect(), variant);
if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(variant, gt.getType());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ public void visitClass(final ClassNode node) {
for (ClassNode anInterface : node.getInterfaces()) {
resolveOrFail(anInterface, "", node, true);
}
/* GRECLIPSE edit -- GROOVY-10113
/* GRECLIPSE edit -- GRECLIPSE-531, GROOVY-10113, GROOVY-10125, et al.
checkCyclicInheritance(node, node.getUnresolvedSuperClass(), node.getInterfaces());
*/
if (sn != null) checkCyclicInheritance(node, sn);
Expand All @@ -1486,7 +1486,7 @@ public void visitClass(final ClassNode node) {
for (GenericsType gt : node.getGenericsTypes()) {
if (gt != null && gt.getUpperBounds() != null) {
for (ClassNode variant : gt.getUpperBounds()) {
if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(gt.getType().redirect(), variant);
if (variant.isGenericsPlaceHolder()) checkCyclicInheritance(variant, gt.getType());
}
}
}
Expand Down

0 comments on commit bf6d32b

Please sign in to comment.