View | Details | Raw Unified | Return to bug 335751
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-1 / +19 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 615-620 Link Here
615
									break firstBound; // do not keep first bound
615
									break firstBound; // do not keep first bound
616
								}
616
								}
617
							}
617
							}
618
							// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335751
619
							if (compilerOptions().complianceLevel > ClassFileConstants.JDK1_6) {
620
								if (typeVariable.rank >= varSuperType.rank && varSuperType.declaringElement == typeVariable.declaringElement) {
621
									SimpleSet set = new SimpleSet(typeParameters.length);
622
									set.add(typeVariable);
623
									ReferenceBinding superBinding = varSuperType;
624
									while (superBinding instanceof TypeVariableBinding) {
625
										if (set.includes(superBinding)) {
626
											problemReporter().hierarchyCircularity(typeVariable, varSuperType, typeRef);
627
											typeVariable.tagBits |= TagBits.HierarchyHasProblems;
628
											break firstBound; // do not keep first bound
629
										} else {
630
											set.add(superBinding);
631
											superBinding = ((TypeVariableBinding)superBinding).superclass;
632
										}
633
									}
634
								}
635
							}
618
							break;
636
							break;
619
						default :
637
						default :
620
							if (((ReferenceBinding) superType).isFinal()) {
638
							if (((ReferenceBinding) superType).isFinal()) {
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-1 / +24 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 2085-2090 Link Here
2085
			end);
2085
			end);
2086
}
2086
}
2087
2087
2088
public void hierarchyCircularity(TypeVariableBinding type, ReferenceBinding superType, TypeReference reference) {
2089
	int start = 0;
2090
	int end = 0;
2091
2092
	start = reference.sourceStart;
2093
	end = reference.sourceEnd;
2094
2095
	if (type == superType)
2096
		this.handle(
2097
			IProblem.HierarchyCircularitySelfReference,
2098
			new String[] {new String(type.readableName()) },
2099
			new String[] {new String(type.shortReadableName()) },
2100
			start,
2101
			end);
2102
	else
2103
		this.handle(
2104
			IProblem.HierarchyCircularity,
2105
			new String[] {new String(type.readableName()), new String(superType.readableName())},
2106
			new String[] {new String(type.shortReadableName()), new String(superType.shortReadableName())},
2107
			start,
2108
			end);
2109
}
2110
2088
public void hierarchyHasProblems(SourceTypeBinding type) {
2111
public void hierarchyHasProblems(SourceTypeBinding type) {
2089
	String[] arguments = new String[] {new String(type.sourceName())};
2112
	String[] arguments = new String[] {new String(type.sourceName())};
2090
	this.handle(
2113
	this.handle(
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java (-2 / +48 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 27-33 Link Here
27
	// Static initializer to specify tests subset using TESTS_* static variables
27
	// Static initializer to specify tests subset using TESTS_* static variables
28
	// All specified tests which does not belong to the class are skipped...
28
	// All specified tests which does not belong to the class are skipped...
29
	static {
29
	static {
30
//		TESTS_NAMES = new String[] { "test322531j" };
30
//		TESTS_NAMES = new String[] { "test335751" };
31
//		TESTS_NAMES = new String[] { "test1464" };
31
//		TESTS_NAMES = new String[] { "test1464" };
32
//		TESTS_NUMBERS = new int[] { 1465 };
32
//		TESTS_NUMBERS = new int[] { 1465 };
33
//		TESTS_RANGE = new int[] { 1097, -1 };
33
//		TESTS_RANGE = new int[] { 1097, -1 };
Lines 1304-1307 Link Here
1304
			"Zork cannot be resolved to a type\n" + 
1304
			"Zork cannot be resolved to a type\n" + 
1305
			"----------\n");
1305
			"----------\n");
1306
}
1306
}
1307
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335751 ([1.7][compiler] Cycle inheritance in type arguments is not detected)
1308
public void test335751() {
1309
	this.runNegativeTest(
1310
			new String[] {
1311
					"X.java",
1312
					"public class X<A extends B, B extends A> {}\n"
1313
			},
1314
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
1315
			"----------\n" + 
1316
			"1. ERROR in X.java (at line 1)\n" + 
1317
			"	public class X<A extends B, B extends A> {}\n" + 
1318
			"	               ^\n" + 
1319
			"Illegal forward reference to type parameter B\n" + 
1320
			"----------\n" : 
1321
1322
			// 1.7+ output.	
1323
			"----------\n" + 
1324
			"1. ERROR in X.java (at line 1)\n" + 
1325
			"	public class X<A extends B, B extends A> {}\n" + 
1326
			"	                                      ^\n" + 
1327
			"Cycle detected: a cycle exists in the type hierarchy between B and A\n" + 
1328
			"----------\n");
1329
}
1330
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=334121 ([1.7][compiler] Stackoverflow error if compiled in 1.7 compliance mode)
1331
public void test334121() {
1332
	this.runNegativeTest(
1333
			new String[] {
1334
					"X.java",
1335
					"public class X<A extends A> {}\n"
1336
			},
1337
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
1338
			"----------\n" + 
1339
			"1. ERROR in X.java (at line 1)\n" + 
1340
			"	public class X<A extends A> {}\n" + 
1341
			"	               ^\n" + 
1342
			"Illegal forward reference to type parameter A\n" + 
1343
			"----------\n" : 
1344
1345
			// 1.7+ output.	
1346
			"----------\n" + 
1347
			"1. ERROR in X.java (at line 1)\n" + 
1348
			"	public class X<A extends A> {}\n" + 
1349
			"	                         ^\n" + 
1350
			"Cycle detected: the type A cannot extend/implement itself or one of its own member types\n" + 
1351
			"----------\n");
1352
}
1307
}
1353
}

Return to bug 335751