View | Details | Raw Unified | Return to bug 312989 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java (+15 lines)
Lines 1187-1192 Link Here
1187
			ReferenceBinding existingType = (ReferenceBinding) existing;
1187
			ReferenceBinding existingType = (ReferenceBinding) existing;
1188
			if (existingType instanceof TypeVariableBinding) {
1188
			if (existingType instanceof TypeVariableBinding) {
1189
				blockScope.problemReporter().typeHiding(this, (TypeVariableBinding) existingType);
1189
				blockScope.problemReporter().typeHiding(this, (TypeVariableBinding) existingType);
1190
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989, check for collision with enclosing type.
1191
				Scope outerScope = blockScope.parent;
1192
checkOuterScope:while (outerScope != null) {
1193
					Binding existing2 = outerScope.getType(this.name);
1194
					if (existing2 == null)
1195
						break checkOuterScope;
1196
					if (existing2 instanceof ReferenceBinding
1197
							&& existing2 != existing
1198
							&& existing2.isValidBinding()
1199
							&& existing2.kind() != Binding.TYPE_PARAMETER) { 
1200
							blockScope.problemReporter().typeCollidesWithEnclosingType(this);
1201
							break checkOuterScope;
1202
					}
1203
					outerScope = outerScope.parent;
1204
				}
1190
			} else if (existingType instanceof LocalTypeBinding
1205
			} else if (existingType instanceof LocalTypeBinding
1191
						&& ((LocalTypeBinding) existingType).scope.methodScope() == blockScope.methodScope()) {
1206
						&& ((LocalTypeBinding) existingType).scope.methodScope() == blockScope.methodScope()) {
1192
					// dup in same method
1207
					// dup in same method
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java (+116 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
import java.util.Map;
14
15
import junit.framework.Test;
16
17
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
18
19
public class InnerClass15Test extends AbstractRegressionTest {
20
public InnerClass15Test(String name) {
21
	super(name);
22
}
23
static {
24
//	TESTS_NUMBERS = new int[] { 2 };
25
}
26
public static Test suite() {
27
	return buildMinimalComplianceTestSuite(testClass(), F_1_5);
28
}
29
protected Map getCompilerOptions() {
30
	Map options = super.getCompilerOptions();
31
	options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
32
	return options;
33
}
34
public void test001() {
35
	this.runNegativeTest(new String[] {
36
		"X.java",
37
		"class X {\n" + 
38
		"	<X> void foo() {\n" + 
39
		"		class X {}\n" + 
40
		"	}\n" + 
41
		"}",
42
	},
43
	"----------\n" + 
44
	"1. WARNING in X.java (at line 2)\n" + 
45
	"	<X> void foo() {\n" + 
46
	"	 ^\n" + 
47
	"The type parameter X is hiding the type X\n" + 
48
	"----------\n" + 
49
	"2. WARNING in X.java (at line 3)\n" + 
50
	"	class X {}\n" + 
51
	"	      ^\n" + 
52
	"The nested type X is hiding the type parameter X of the generic method foo() of type X\n" + 
53
	"----------\n" + 
54
	"3. ERROR in X.java (at line 3)\n" + 
55
	"	class X {}\n" + 
56
	"	      ^\n" + 
57
	"The nested type X cannot hide an enclosing type\n" + 
58
	"----------\n");
59
}
60
public void test002() {
61
	this.runNegativeTest(new String[] {
62
		"X.java",
63
		"class X<X> {\n" + 
64
		"	void foo() {\n" + 
65
		"		class X {}\n" + 
66
		"	}\n" + 
67
		"}",
68
	},
69
	"----------\n" + 
70
	"1. WARNING in X.java (at line 1)\n" + 
71
	"	class X<X> {\n" + 
72
	"	        ^\n" + 
73
	"The type parameter X is hiding the type X<X>\n" + 
74
	"----------\n" + 
75
	"2. WARNING in X.java (at line 3)\n" + 
76
	"	class X {}\n" + 
77
	"	      ^\n" + 
78
	"The nested type X is hiding the type parameter X of type X<X>\n" + 
79
	"----------\n" + 
80
	"3. ERROR in X.java (at line 3)\n" + 
81
	"	class X {}\n" + 
82
	"	      ^\n" + 
83
	"The nested type X cannot hide an enclosing type\n" + 
84
	"----------\n");
85
}
86
public void test003() {
87
	this.runNegativeTest(new String[] {
88
		"Y.java",
89
		"class Y {\n" +
90
		"class X {}\n" + 
91
		"	<X> void foo() {\n" + 
92
		"		class X {}\n" + 
93
		"	}\n" + 
94
		"}",
95
	},
96
	"----------\n" + 
97
	"1. WARNING in Y.java (at line 3)\n" + 
98
	"	<X> void foo() {\n" + 
99
	"	 ^\n" + 
100
	"The type parameter X is hiding the type Y.X\n" + 
101
	"----------\n" + 
102
	"2. WARNING in Y.java (at line 4)\n" + 
103
	"	class X {}\n" + 
104
	"	      ^\n" + 
105
	"The nested type X is hiding the type parameter X of the generic method foo() of type Y\n" + 
106
	"----------\n" + 
107
	"3. ERROR in Y.java (at line 4)\n" + 
108
	"	class X {}\n" + 
109
	"	      ^\n" + 
110
	"The nested type X cannot hide an enclosing type\n" + 
111
	"----------\n");
112
}
113
public static Class testClass() {
114
	return InnerClass15Test.class;
115
}
116
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java (+1 lines)
Lines 94-99 Link Here
94
	since_1_5.add(Deprecated15Test.class);
94
	since_1_5.add(Deprecated15Test.class);
95
	since_1_5.add(InnerEmulationTest_1_5.class);
95
	since_1_5.add(InnerEmulationTest_1_5.class);
96
	since_1_5.add(AssignmentTest_1_5.class);
96
	since_1_5.add(AssignmentTest_1_5.class);
97
	since_1_5.add(InnerClass15Test.class);
97
98
98
	// Tests to run when compliance is greater than 1.5
99
	// Tests to run when compliance is greater than 1.5
99
	ArrayList since_1_6 = new ArrayList();
100
	ArrayList since_1_6 = new ArrayList();

Return to bug 312989