Skip to content

Commit 2cd10d4

Browse files
committed
GROOVY-10113
1 parent 848fd1c commit 2cd10d4

File tree

30 files changed

+633
-189
lines changed

30 files changed

+633
-189
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java

+196-77
Original file line numberDiff line numberDiff line change
@@ -1014,152 +1014,271 @@ public void testClash_GRE1076_2() {
10141014
}
10151015

10161016
@Test
1017-
public void testCyclicReference() {
1017+
public void testCyclicReference1() {
10181018
//@formatter:off
10191019
String[] sources = {
1020-
"p/B.groovy",
1021-
"package p;\n" +
1022-
"class B extends B<String> {\n" +
1023-
" public static void main(String[] argv) {\n" +
1024-
" new B();\n" +
1025-
" print \"success\"\n" +
1020+
"C.groovy",
1021+
"class C extends C {\n" +
1022+
"}\n",
1023+
};
1024+
//@formatter:on
1025+
1026+
runNegativeTest(sources,
1027+
"----------\n" +
1028+
"1. ERROR in C.groovy (at line 1)\n" +
1029+
"\tclass C extends C {\n" +
1030+
"\t ^\n" +
1031+
"Groovy:Cycle detected: the type C cannot extend/implement itself or one of its own member types\n" +
1032+
"----------\n");
1033+
}
1034+
1035+
@Test
1036+
public void testCyclicReference2() {
1037+
//@formatter:off
1038+
String[] sources = {
1039+
"I.groovy",
1040+
"interface I extends I {\n" +
1041+
"}\n",
1042+
};
1043+
//@formatter:on
1044+
1045+
runNegativeTest(sources,
1046+
"----------\n" +
1047+
"1. ERROR in I.groovy (at line 1)\n" +
1048+
"\tinterface I extends I {\n" +
1049+
"\t ^\n" +
1050+
"Groovy:Cycle detected: the type I cannot extend/implement itself or one of its own member types\n" +
1051+
"----------\n");
1052+
}
1053+
1054+
@Test
1055+
public void testCyclicReference3() {
1056+
//@formatter:off
1057+
String[] sources = {
1058+
"C.groovy",
1059+
"class C extends C.D {\n" +
1060+
" class D {\n" +
10261061
" }\n" +
10271062
"}\n",
1063+
};
1064+
//@formatter:on
10281065

1029-
"p/A.java",
1030-
"package p;\n" +
1031-
"public class A<T> {}\n",
1066+
runNegativeTest(sources,
1067+
"----------\n" +
1068+
"1. ERROR in C.groovy (at line 1)\n" +
1069+
"\tclass C extends C.D {\n" +
1070+
"\t ^^^\n" +
1071+
"Groovy:Cycle detected: the type C cannot extend/implement itself or one of its own member types\n" +
1072+
"----------\n");
1073+
}
1074+
1075+
@Test // GROOVY-10124
1076+
public void testCyclicReference4() {
1077+
//@formatter:off
1078+
String[] sources = {
1079+
"C.groovy",
1080+
"class C extends D {\n" +
1081+
" class D {\n" +
1082+
" }\n" +
1083+
"}\n",
10321084
};
10331085
//@formatter:on
10341086

10351087
runNegativeTest(sources,
10361088
"----------\n" +
1037-
"1. ERROR in p\\B.groovy (at line 2)\n" +
1038-
"\tclass B extends B<String> {\n" +
1039-
"\t ^\n" +
1040-
"Groovy:Cyclic inheritance involving p.B in class p.B\n" +
1089+
"1. ERROR in C.groovy (at line 1)\n" +
1090+
"\tclass C extends D {\n" +
1091+
"\t ^\n" +
1092+
"Groovy:Cycle detected: the type C cannot extend/implement itself or one of its own member types\n" +
1093+
"----------\n");
1094+
}
1095+
1096+
@Test // GROOVY-10113
1097+
public void testCyclicReference5() {
1098+
//@formatter:off
1099+
String[] sources = {
1100+
"C.groovy",
1101+
"class C<T extends T> {\n" +
1102+
"}\n",
1103+
};
1104+
//@formatter:on
1105+
1106+
runNegativeTest(sources,
1107+
"----------\n" +
1108+
"1. ERROR in C.groovy (at line 1)\n" +
1109+
"\tclass C<T extends T> {\n" +
1110+
"\t ^\n" +
1111+
"Groovy:Cycle detected: the type T cannot extend/implement itself or one of its own member types\n" +
1112+
"----------\n");
1113+
}
1114+
1115+
@Test
1116+
public void testCyclicReference6() {
1117+
//@formatter:off
1118+
String[] sources = {
1119+
"C.groovy",
1120+
"class C extends C<String> {\n" +
1121+
"}\n",
1122+
};
1123+
//@formatter:on
1124+
1125+
runNegativeTest(sources,
10411126
"----------\n" +
1042-
"2. ERROR in p\\B.groovy (at line 2)\n" +
1043-
"\tclass B extends B<String> {\n" +
1127+
"1. ERROR in C.groovy (at line 1)\n" +
1128+
"\tclass C extends C<String> {\n" +
10441129
"\t ^\n" +
1045-
"Cycle detected: the type B cannot extend/implement itself or one of its own member types\n" +
1130+
"Groovy:Cycle detected: the type C cannot extend/implement itself or one of its own member types\n" +
10461131
"----------\n");
10471132
}
10481133

10491134
@Test
1050-
public void testCyclicReference_GR531() {
1135+
public void testCyclicReference7() {
10511136
//@formatter:off
10521137
String[] sources = {
1053-
"XXX.groovy",
1054-
"class XXX extends XXX {\n" +
1138+
"C.groovy",
1139+
"class C extends D {\n" +
1140+
"}\n",
1141+
1142+
"D.groovy",
1143+
"class D extends C {\n" +
10551144
"}\n",
10561145
};
10571146
//@formatter:on
10581147

10591148
runNegativeTest(sources,
10601149
"----------\n" +
1061-
"1. ERROR in XXX.groovy (at line 1)\n" +
1062-
"\tclass XXX extends XXX {\n" +
1063-
"\t ^^^\n" +
1064-
"Groovy:Cyclic inheritance involving XXX in class XXX\n" +
1150+
"1. ERROR in C.groovy (at line 1)\n" +
1151+
"\tclass C extends D {\n" +
1152+
"\t ^\n" +
1153+
"The hierarchy of the type C is inconsistent\n" +
1154+
"----------\n" +
10651155
"----------\n" +
1066-
"2. ERROR in XXX.groovy (at line 1)\n" +
1067-
"\tclass XXX extends XXX {\n" +
1068-
"\t ^^^\n" +
1069-
"Cycle detected: the type XXX cannot extend/implement itself or one of its own member types\n" +
1156+
"1. ERROR in D.groovy (at line 1)\n" +
1157+
"\tclass D extends C {\n" +
1158+
"\t ^\n" +
1159+
"Groovy:Cycle detected: a cycle exists in the type hierarchy between D and C\n" +
10701160
"----------\n");
10711161
}
10721162

10731163
@Test
1074-
public void testCyclicReference_GR531_2() {
1164+
public void testCyclicReference8() {
10751165
//@formatter:off
10761166
String[] sources = {
1077-
"XXX.groovy",
1078-
"class XXX extends XXX {\n" +
1079-
" public static void main(String[] argv) {\n" +
1080-
" print \"success\"\n" +
1081-
" }\n" +
1167+
"I.groovy",
1168+
"interface I extends J {\n" +
1169+
"}\n",
1170+
1171+
"J.groovy",
1172+
"interface J extends I {\n" +
10821173
"}\n",
10831174
};
10841175
//@formatter:on
10851176

10861177
runNegativeTest(sources,
10871178
"----------\n" +
1088-
"1. ERROR in XXX.groovy (at line 1)\n" +
1089-
"\tclass XXX extends XXX {\n" +
1090-
"\t ^^^\n" +
1091-
"Groovy:Cyclic inheritance involving XXX in class XXX\n" +
1179+
"1. ERROR in I.groovy (at line 1)\n" +
1180+
"\tinterface I extends J {\n" +
1181+
"\t ^\n" +
1182+
"The hierarchy of the type I is inconsistent\n" +
1183+
"----------\n" +
10921184
"----------\n" +
1093-
"2. ERROR in XXX.groovy (at line 1)\n" +
1094-
"\tclass XXX extends XXX {\n" +
1095-
"\t ^^^\n" +
1096-
"Cycle detected: the type XXX cannot extend/implement itself or one of its own member types\n" +
1185+
"1. ERROR in J.groovy (at line 1)\n" +
1186+
"\tinterface J extends I {\n" +
1187+
"\t ^\n" +
1188+
"Groovy:Cycle detected: a cycle exists in the type hierarchy between J and I\n" +
10971189
"----------\n");
10981190
}
10991191

11001192
@Test
1101-
public void testCyclicReference_GR531_3() {
1193+
public void testCyclicReference9() {
11021194
//@formatter:off
11031195
String[] sources = {
1104-
"XXX.groovy",
1105-
"class XXX extends YYY {\n" +
1106-
" public static void main(String[] argv) {\n" +
1107-
" print \"success\"\n" +
1196+
"C.groovy",
1197+
"class C extends D {\n" +
1198+
" interface I {\n" +
11081199
" }\n" +
11091200
"}\n",
1110-
"YYY.groovy",
1111-
"class YYY extends XXX {\n" +
1112-
" public static void main(String[] argv) {\n" +
1113-
" print \"success\"\n" +
1114-
" }\n" +
1201+
1202+
"D.groovy",
1203+
"class D implements C.I {\n" +
11151204
"}\n",
11161205
};
11171206
//@formatter:on
11181207

11191208
runNegativeTest(sources,
11201209
"----------\n" +
1121-
"1. ERROR in XXX.groovy (at line 1)\n" +
1122-
"\tclass XXX extends YYY {\n" +
1123-
"\t ^^^\n" +
1124-
"The hierarchy of the type XXX is inconsistent\n" +
1125-
"----------\n" +
1210+
"1. ERROR in C.groovy (at line 1)\n" +
1211+
"\tclass C extends D {\n" +
1212+
"\t ^\n" +
1213+
"The hierarchy of the type C is inconsistent\n" +
11261214
"----------\n" +
1127-
"1. ERROR in YYY.groovy (at line 1)\n" +
1128-
"\tclass YYY extends XXX {\n" +
1129-
"\t ^^^\n" +
1130-
"Groovy:Cyclic inheritance involving YYY in class YYY\n" +
11311215
"----------\n" +
1132-
"2. ERROR in YYY.groovy (at line 1)\n" +
1133-
"\tclass YYY extends XXX {\n" +
1134-
"\t ^^^\n" +
1135-
"Cycle detected: a cycle exists in the type hierarchy between YYY and XXX\n" +
1216+
"1. ERROR in D.groovy (at line 1)\n" +
1217+
"\tclass D implements C.I {\n" +
1218+
"\t ^^^\n" +
1219+
"Groovy:Cycle detected: a cycle exists in the type hierarchy between D and C\n" +
11361220
"----------\n");
11371221
}
11381222

1139-
@Test
1140-
public void testCyclicReference_GR531_4() {
1223+
@Test // typo that caused overflow
1224+
public void testCyclicReference10() {
11411225
//@formatter:off
11421226
String[] sources = {
1143-
"XXX.groovy",
1144-
"interface XXX extends XXX {\n" +
1227+
"A.groovy",
1228+
"interface A extends B {\n" +
1229+
"}\n",
1230+
1231+
"B.groovy",
1232+
"class B extends A {\n" +
11451233
"}\n",
11461234
};
11471235
//@formatter:on
11481236

11491237
runNegativeTest(sources,
11501238
"----------\n" +
1151-
"1. ERROR in XXX.groovy (at line 1)\n" +
1152-
"\tinterface XXX extends XXX {\n" +
1153-
"\t ^^^\n" +
1154-
"Groovy:Cyclic inheritance involving XXX in interface XXX\n" +
1239+
"1. ERROR in A.groovy (at line 1)\n" +
1240+
"\tinterface A extends B {\n" +
1241+
"\t ^\n" +
1242+
"Groovy:You are not allowed to implement the class 'B', use extends instead.\n" +
1243+
"----------\n" +
11551244
"----------\n" +
1156-
"2. ERROR in XXX.groovy (at line 1)\n" +
1157-
"\tinterface XXX extends XXX {\n" +
1158-
"\t ^^^\n" +
1159-
"Cycle detected: the type XXX cannot extend/implement itself or one of its own member types\n" +
1245+
"1. ERROR in B.groovy (at line 1)\n" +
1246+
"\tclass B extends A {\n" +
1247+
"\t ^\n" +
1248+
"Groovy:Cycle detected: a cycle exists in the type hierarchy between B and A\n" +
11601249
"----------\n");
11611250
}
11621251

1252+
@Test
1253+
public void testNonCyclicReference1() {
1254+
//@formatter:off
1255+
String[] sources = {
1256+
"C.groovy",
1257+
"@SuppressWarnings('rawtypes')\n" +
1258+
"class C<T extends C> {\n" +
1259+
"}\n",
1260+
};
1261+
//@formatter:on
1262+
1263+
runNegativeTest(sources, "");
1264+
}
1265+
1266+
@Test
1267+
public void testNonCyclicReference2() {
1268+
//@formatter:off
1269+
String[] sources = {
1270+
"C.groovy",
1271+
"@SuppressWarnings('rawtypes')\n" +
1272+
"class C<T extends C.D> {\n" +
1273+
" class D {\n" +
1274+
" }\n" +
1275+
"}\n",
1276+
};
1277+
//@formatter:on
1278+
1279+
runNegativeTest(sources, "");
1280+
}
1281+
11631282
@Test
11641283
public void testUnreachable_1047() {
11651284
//@formatter:off

0 commit comments

Comments
 (0)