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 (+22 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 instanceof TypeVariableBinding && existing2.isValidBinding()) {
1195
						TypeVariableBinding tvb = (TypeVariableBinding) existingType;
1196
						Binding declaringElement = tvb.declaringElement;
1197
						if (declaringElement instanceof ReferenceBinding
1198
								&& CharOperation.equals(((ReferenceBinding) declaringElement).sourceName(), this.name)) {
1199
							blockScope.problemReporter().typeCollidesWithEnclosingType(this);
1200
							break checkOuterScope;
1201
						}
1202
					} else if (existing2 instanceof ReferenceBinding
1203
							&& existing2.isValidBinding()
1204
							&& outerScope.isDefinedInType((ReferenceBinding) existing2)) { 
1205
							blockScope.problemReporter().typeCollidesWithEnclosingType(this);
1206
							break checkOuterScope;
1207
					} else if (existing2 == null) {
1208
						break checkOuterScope;
1209
					}
1210
					outerScope = outerScope.parent;
1211
				}
1190
			} else if (existingType instanceof LocalTypeBinding
1212
			} else if (existingType instanceof LocalTypeBinding
1191
						&& ((LocalTypeBinding) existingType).scope.methodScope() == blockScope.methodScope()) {
1213
						&& ((LocalTypeBinding) existingType).scope.methodScope() == blockScope.methodScope()) {
1192
					// dup in same method
1214
					// dup in same method
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java (+142 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
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989
87
// note javac reports an error for this test, but that is
88
// incorrect, compare and contrast javac behavior with
89
// test004.
90
public void test003() {
91
	this.runNegativeTest(new String[] {
92
		"Y.java",
93
		"class Y {\n" +
94
		"class X {}\n" + 
95
		"	<X> void foo() {\n" + 
96
		"		class X {}\n" + 
97
		"	}\n" + 
98
		"}",
99
	},
100
	"----------\n" + 
101
	"1. WARNING in Y.java (at line 3)\n" + 
102
	"	<X> void foo() {\n" + 
103
	"	 ^\n" + 
104
	"The type parameter X is hiding the type Y.X\n" + 
105
	"----------\n" + 
106
	"2. WARNING in Y.java (at line 4)\n" + 
107
	"	class X {}\n" + 
108
	"	      ^\n" + 
109
	"The nested type X is hiding the type parameter X of the generic method foo() of type Y\n" + 
110
	"----------\n" + 
111
	"3. WARNING in Y.java (at line 4)\n" + 
112
	"	class X {}\n" + 
113
	"	      ^\n" + 
114
	"The type X is never used locally\n" + 
115
	"----------\n");
116
}
117
public void test004() {
118
	this.runNegativeTest(new String[] {
119
		"Y.java",
120
		"class Y {\n" +
121
		"class X {}\n" + 
122
		"   void foo() {\n" + 
123
		"		class X {}\n" + 
124
		"	}\n" + 
125
		"}",
126
	},
127
	"----------\n" + 
128
	"1. WARNING in Y.java (at line 4)\n" + 
129
	"	class X {}\n" + 
130
	"	      ^\n" + 
131
	"The type X is hiding the type Y.X\n" + 
132
	"----------\n" + 
133
	"2. WARNING in Y.java (at line 4)\n" + 
134
	"	class X {}\n" + 
135
	"	      ^\n" + 
136
	"The type X is never used locally\n" + 
137
	"----------\n");
138
}
139
public static Class testClass() {
140
	return InnerClass15Test.class;
141
}
142
}
(-)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