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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-6 / +11 lines)
Lines 2596-2609 Link Here
2596
				TypeBinding oneParam = oneParams[i];
2596
				TypeBinding oneParam = oneParams[i];
2597
				TypeBinding twoParam = twoParams[i];
2597
				TypeBinding twoParam = twoParams[i];
2598
				if (oneParam == twoParam) {
2598
				if (oneParam == twoParam) {
2599
					if (oneParam.leafComponentType().isRawType()) {
2599
					if (twoParam.leafComponentType().isRawType()) {
2600
						// A#RAW is not more specific than a rawified A<T>
2600
						// must detect & reject this case
2601
						if (oneParam == one.original().parameters[i] && oneParam != two.original().parameters[i])
2601
						// when Y<U> extends X<U>
2602
						// void foo(Y y) {}
2603
						// <T extends X<Object>> void foo(T t) {}
2604
						// foo(T) will show up as foo(Y#RAW) and not foo(X#RAW)
2605
						// Y#RAW is not more specific than a rawified X<T>
2606
						if (oneParam == one.original().parameters[i]
2607
								&&  twoParam.leafComponentType().erasure() != two.original().parameters[i].leafComponentType().erasure()) {
2602
							return false;
2608
							return false;
2609
						}
2603
					}
2610
					}
2604
					continue;
2611
				} else if (oneParam.isCompatibleWith(twoParam)) {
2605
				}
2606
				if (oneParam.isCompatibleWith(twoParam)) {
2607
					if (oneParam.leafComponentType().isRawType()) {
2612
					if (oneParam.leafComponentType().isRawType()) {
2608
						// A#RAW is not more specific than a rawified A<T>
2613
						// A#RAW is not more specific than a rawified A<T>
2609
						if (oneParam.needsUncheckedConversion(two.declaringClass.isRawType() ? twoParam : two.original().parameters[i]))
2614
						if (oneParam.needsUncheckedConversion(two.declaringClass.isRawType() ? twoParam : two.original().parameters[i]))
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+107 lines)
Lines 41119-41122 Link Here
41119
			false,
41119
			false,
41120
			null);		
41120
			null);		
41121
}
41121
}
41122
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843
41123
public void test1232() {
41124
	this.runConformTest(
41125
		new String[] {
41126
			"X.java",
41127
			"public class X {\n" + 
41128
			"	public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + 
41129
			"		SubInterface sub3 = sub1.and(sub2);\n" + 
41130
			"	}\n" + 
41131
			"	public interface SuperInterface<E> {\n" + 
41132
			"		public Number getNumber();\n" + 
41133
			"		public SuperInterface<E> and(SuperInterface<E> a);\n" + 
41134
			"	}\n" + 
41135
			"	public interface SubInterface extends SuperInterface {\n" + 
41136
			"		public Integer getNumber();\n" + 
41137
			"		public SubInterface and(SuperInterface s);\n" + 
41138
			"	}\n" + 
41139
			"}\n",
41140
		},
41141
		"");
41142
	
41143
}
41144
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation
41145
public void test1233() {
41146
	this.runConformTest(
41147
		new String[] {
41148
			"X.java",
41149
			"public class X {\n" + 
41150
			"	public static void testCovariant(SubInterface<String> sub1, SubInterface<String> sub2) {\n" + 
41151
			"		SubInterface<String> sub3 = sub1.and(sub2);\n" + 
41152
			"	}\n" + 
41153
			"	public interface SuperInterface<E> {\n" + 
41154
			"		public Number getNumber();\n" + 
41155
			"		public SuperInterface<E> and(SuperInterface<E> a);\n" + 
41156
			"	}\n" + 
41157
			"	public interface SubInterface<F> extends SuperInterface<F> {\n" + 
41158
			"		public Integer getNumber();\n" + 
41159
			"		public SubInterface<F> and(SuperInterface<F> s);\n" + 
41160
			"	}\n" + 
41161
			"}\n",
41162
		},
41163
		"");
41164
}
41165
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation
41166
public void test1234() {
41167
	this.runNegativeTest(
41168
		new String[] {
41169
			"X.java",
41170
			"public class X { \n" + 
41171
			"	void a3(G x) {} \n" + 
41172
			"	<T extends F<X>> void a3(T x) {}\n" + 
41173
			"\n" + 
41174
			"	public static void ambiguousCases() { \n" + 
41175
			"		H<X> hx = null;\n" + 
41176
			"		H hraw = null;\n" + 
41177
			"		new X().a3(hx);\n" + 
41178
			"		new X().a3(hraw);\n" + 
41179
			"	} \n" + 
41180
			"}\n" + 
41181
			"class F<T1> {}  \n" + 
41182
			"class G<T2> extends F<T2> {}\n" + 
41183
			"class H<T3> extends G<T3> {}\n",
41184
		},
41185
		"----------\n" + 
41186
		"1. WARNING in X.java (at line 2)\n" + 
41187
		"	void a3(G x) {} \n" + 
41188
		"	        ^\n" + 
41189
		"G is a raw type. References to generic type G<T2> should be parameterized\n" + 
41190
		"----------\n" + 
41191
		"2. WARNING in X.java (at line 7)\n" + 
41192
		"	H hraw = null;\n" + 
41193
		"	^\n" + 
41194
		"H is a raw type. References to generic type H<T3> should be parameterized\n" + 
41195
		"----------\n" + 
41196
		"3. ERROR in X.java (at line 8)\n" + 
41197
		"	new X().a3(hx);\n" + 
41198
		"	        ^^\n" + 
41199
		"The method a3(G) is ambiguous for the type X\n" + 
41200
		"----------\n" + 
41201
		"4. ERROR in X.java (at line 9)\n" + 
41202
		"	new X().a3(hraw);\n" + 
41203
		"	        ^^\n" + 
41204
		"The method a3(G) is ambiguous for the type X\n" + 
41205
		"----------\n");
41206
}
41207
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation
41208
public void test1235() {
41209
	this.runConformTest(
41210
		new String[] {
41211
			"X.java",
41212
			"public class X { \n" + 
41213
			"	<T extends G<X>> void a3(T x) {}\n" + 
41214
			"	<T extends F<X>> void a3(T x) {}\n" + 
41215
			"\n" + 
41216
			"	public static void ambiguousCases() { \n" + 
41217
			"		H<X> hx = null;\n" + 
41218
			"		H hraw = null;\n" + 
41219
			"		new X().a3(hx);\n" + 
41220
			"		new X().a3(hraw);\n" + 
41221
			"	} \n" + 
41222
			"}\n" + 
41223
			"class F<T1> {}  \n" + 
41224
			"class G<T2> extends F<T2> {}\n" + 
41225
			"class H<T3> extends G<T3> {}\n",
41226
		},
41227
		"");
41228
}
41122
}
41229
}

Return to bug 215843