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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-14 / +68 lines)
Lines 898-904 Link Here
898
			// in >= 1.5 mode, ensure the exactMatch did not match raw types
898
			// in >= 1.5 mode, ensure the exactMatch did not match raw types
899
			if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5)
899
			if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5)
900
				for (int i = argumentTypes.length; --i >= 0;)
900
				for (int i = argumentTypes.length; --i >= 0;)
901
					if (argumentTypes[i].isRawType())
901
					if (isSubtypeOfRawType(argumentTypes[i]))
902
						return null;
902
						return null;
903
			// must find both methods for this case: <S extends A> void foo() {}  and  <N extends B> N foo() { return null; }
903
			// must find both methods for this case: <S extends A> void foo() {}  and  <N extends B> N foo() { return null; }
904
			// or find an inherited method when the exact match is to a bridge method
904
			// or find an inherited method when the exact match is to a bridge method
Lines 2784-2805 Link Here
2784
				if (oneParam == twoParam || oneParam.isCompatibleWith(twoParam)) {
2784
				if (oneParam == twoParam || oneParam.isCompatibleWith(twoParam)) {
2785
					if (two.declaringClass.isRawType()) continue next;
2785
					if (two.declaringClass.isRawType()) continue next;
2786
2786
2787
					TypeBinding originalOneParam = one.original().parameters[i].leafComponentType();
2787
					TypeBinding originalTwoParam = two.original().parameters[i].leafComponentType();
2788
					switch (originalOneParam.kind()) {
2788
					switch (originalTwoParam.kind()) {
2789
					   	case Binding.TYPE_PARAMETER :
2789
					   	case Binding.TYPE_PARAMETER :
2790
					   		if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType()) break;
2790
					   		if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds())
2791
						   		continue next;
2791
					   		//$FALL-THROUGH$
2792
					   		//$FALL-THROUGH$
2792
					   	case Binding.RAW_TYPE:
2793
					   	case Binding.WILDCARD_TYPE :
2793
					   		// originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type
2794
					   	case Binding.INTERSECTION_TYPE:
2794
							TypeBinding originalTwoParam = two.original().parameters[i].leafComponentType();
2795
					   	case Binding.PARAMETERIZED_TYPE :
2795
							switch (originalTwoParam.kind()) {
2796
							TypeBinding originalOneParam = one.original().parameters[i].leafComponentType();
2797
							switch (originalOneParam.kind()) {
2798
							   	case Binding.TYPE :
2799
							   	case Binding.GENERIC_TYPE :
2800
									TypeBinding inheritedTwoParam = oneParam.findSuperTypeOriginatingFrom(twoParam);
2801
									if (inheritedTwoParam == null || !inheritedTwoParam.leafComponentType().isRawType()) break;
2802
							   		return false;
2796
							   	case Binding.TYPE_PARAMETER :
2803
							   	case Binding.TYPE_PARAMETER :
2797
							   		if (((TypeVariableBinding) originalTwoParam).hasOnlyRawBounds())
2804
							   		if (!((TypeVariableBinding) originalOneParam).upperBound().isRawType()) break;
2798
								   		continue next;
2805
							   		return false;
2799
								   	return false;
2806
							   	case Binding.RAW_TYPE:
2800
							   	case Binding.WILDCARD_TYPE :
2807
							   		// originalOneParam is RAW so it cannot be more specific than a wildcard or parameterized type
2801
							   	case Binding.INTERSECTION_TYPE:
2802
							   	case Binding.PARAMETERIZED_TYPE :
2803
							   		return false;
2808
							   		return false;
2804
							}
2809
							}
2805
					}
2810
					}
Lines 2970-2975 Link Here
2970
		return false;
2975
		return false;
2971
	}
2976
	}
2972
2977
2978
	public boolean isSubtypeOfRawType(TypeBinding paramType) {
2979
		TypeBinding t = paramType.leafComponentType();
2980
		if (t.isBaseType()) return false;
2981
2982
		ReferenceBinding currentType = (ReferenceBinding) t;
2983
		ReferenceBinding[] interfacesToVisit = null;
2984
		int nextPosition = 0;
2985
		do {
2986
			if (currentType.isRawType()) return true;
2987
	
2988
			ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
2989
			if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
2990
				if (interfacesToVisit == null) {
2991
					interfacesToVisit = itsInterfaces;
2992
					nextPosition = interfacesToVisit.length;
2993
				} else {
2994
					int itsLength = itsInterfaces.length;
2995
					if (nextPosition + itsLength >= interfacesToVisit.length)
2996
						System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
2997
					nextInterface : for (int a = 0; a < itsLength; a++) {
2998
						ReferenceBinding next = itsInterfaces[a];
2999
						for (int b = 0; b < nextPosition; b++)
3000
							if (next == interfacesToVisit[b]) continue nextInterface;
3001
						interfacesToVisit[nextPosition++] = next;
3002
					}
3003
				}
3004
			}
3005
		} while ((currentType = currentType.superclass()) != null);
3006
3007
		for (int i = 0; i < nextPosition; i++) {
3008
			currentType = interfacesToVisit[i];
3009
			if (currentType.isRawType()) return true;
3010
3011
			ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
3012
			if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
3013
				int itsLength = itsInterfaces.length;
3014
				if (nextPosition + itsLength >= interfacesToVisit.length)
3015
					System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition);
3016
				nextInterface : for (int a = 0; a < itsLength; a++) {
3017
					ReferenceBinding next = itsInterfaces[a];
3018
					for (int b = 0; b < nextPosition; b++)
3019
						if (next == interfacesToVisit[b]) continue nextInterface;
3020
					interfacesToVisit[nextPosition++] = next;
3021
				}
3022
			}
3023
		}
3024
		return false;
3025
	}
3026
2973
	private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocationData, List lubStack) {
3027
	private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocationData, List lubStack) {
2974
		if (invocationData == null) return mec; // no alternate invocation
3028
		if (invocationData == null) return mec; // no alternate invocation
2975
		if (invocationData instanceof TypeBinding) { // only one invocation, simply return it (array only allocated if more than one)
3029
		if (invocationData instanceof TypeBinding) { // only one invocation, simply return it (array only allocated if more than one)
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java (-2 lines)
Lines 327-334 Link Here
327
		public static EclipseHasABug
327
		public static EclipseHasABug
328
			EclipseBug159851 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851
328
			EclipseBug159851 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851
329
				new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null,
329
				new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null,
330
			EclipseBug166355 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
331
				new EclipseHasABug(MismatchType.JavacErrorsEclipseWarnings) : null,
332
			EclipseBug177715 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715
330
			EclipseBug177715 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715
333
				new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null,
331
				new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null,
334
			EclipseBug207935 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935
332
			EclipseBug207935 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java (-40 / +140 lines)
Lines 2163-2171 Link Here
2163
}
2163
}
2164
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2164
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2165
public void test051() {
2165
public void test051() {
2166
	this.runConformTest(
2166
	this.runNegativeTest(
2167
		// test directory preparation
2168
		true /* flush output directory */,
2169
		new String[] { /* test files */
2167
		new String[] { /* test files */
2170
			"X.java",
2168
			"X.java",
2171
			"interface I<T> {\n" +
2169
			"interface I<T> {\n" +
Lines 2184-2206 Link Here
2184
			"  }\n" +
2182
			"  }\n" +
2185
			"}\n"
2183
			"}\n"
2186
		},
2184
		},
2187
		// compiler results
2185
		"----------\n" + 
2188
		"----------\n" + /* expected compiler log */
2186
		"1. ERROR in X.java (at line 9)\n" + 
2189
		"1. WARNING in X.java (at line 9)\n" +
2187
		"	bar(new Z());\n" + 
2190
		"	bar(new Z());\n" +
2188
		"	^^^\n" + 
2191
		"	    ^^^^^^^\n" +
2189
		"The method bar(X.Z) is ambiguous for the type X\n" + 
2192
		"Access to enclosing constructor X.Z() is emulated by a synthetic accessor method\n" +
2190
		"----------\n" + 
2193
		"----------\n" +
2191
		"2. WARNING in X.java (at line 13)\n" + 
2194
		"2. WARNING in X.java (at line 13)\n" +
2192
		"	private static final class Z implements I {\n" + 
2195
		"	private static final class Z implements I {\n" +
2193
		"	                                        ^\n" + 
2196
		"	                                        ^\n" +
2194
		"I is a raw type. References to generic type I<T> should be parameterized\n" + 
2197
		"I is a raw type. References to generic type I<T> should be parameterized\n" +
2195
		"----------\n");
2198
		"----------\n",
2199
		// runtime options
2200
		"" /* expected output string */,
2201
		"" /* do not check error string */,
2202
		// javac options
2203
		JavacTestOptions.EclipseHasABug.EclipseBug166355 /* javac test options */);
2204
}
2196
}
2205
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2197
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2206
// variant
2198
// variant
Lines 2229-2237 Link Here
2229
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2221
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2230
// variant
2222
// variant
2231
public void test053() {
2223
public void test053() {
2232
	this.runConformTest(
2224
	this.runNegativeTest(
2233
		// test directory preparation
2234
		true /* flush output directory */,
2235
		new String[] { /* test files */
2225
		new String[] { /* test files */
2236
			"X.java",
2226
			"X.java",
2237
			"interface I<T> {\n" +
2227
			"interface I<T> {\n" +
Lines 2250-2272 Link Here
2250
			"  }\n" +
2240
			"  }\n" +
2251
			"}\n"
2241
			"}\n"
2252
		},
2242
		},
2253
		// compiler results
2243
		"----------\n" + 
2254
		"----------\n" + /* expected compiler log */
2244
		"1. ERROR in X.java (at line 9)\n" + 
2255
		"1. WARNING in X.java (at line 9)\n" +
2245
		"	bar(new Z(){});\n" + 
2256
		"	bar(new Z(){});\n" +
2246
		"	^^^\n" + 
2257
		"	        ^^^\n" +
2247
		"The method bar(X.Z) is ambiguous for the type X\n" + 
2258
		"Access to enclosing constructor X.Z() is emulated by a synthetic accessor method\n" +
2248
		"----------\n" + 
2259
		"----------\n" +
2249
		"2. WARNING in X.java (at line 13)\n" + 
2260
		"2. WARNING in X.java (at line 13)\n" +
2250
		"	private static class Z implements I {\n" + 
2261
		"	private static class Z implements I {\n" +
2251
		"	                                  ^\n" + 
2262
		"	                                  ^\n" +
2252
		"I is a raw type. References to generic type I<T> should be parameterized\n" + 
2263
		"I is a raw type. References to generic type I<T> should be parameterized\n" +
2253
		"----------\n");
2264
		"----------\n",
2265
		// runtime results
2266
		"" /* expected output string */,
2267
		"" /* expected error string */,
2268
		// javac options
2269
		JavacTestOptions.EclipseHasABug.EclipseBug166355 /* javac test options */);
2270
}
2254
}
2271
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2255
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355
2272
// variant
2256
// variant
Lines 2937-2940 Link Here
2937
		"----------\n"
2921
		"----------\n"
2938
	);
2922
	);
2939
}
2923
}
2924
2925
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=206930
2926
public void test074() {
2927
	this.runNegativeTest(
2928
		new String[] {
2929
			"Y.java",
2930
			"interface I<T> {}\n" +
2931
			"class A {\n" +
2932
			"	void a(I x) {}\n" +
2933
			"	void b(I<?> x) {}\n" +
2934
			"	void b(I<?>[] x) {}\n" +
2935
			"	<U> void c(I<?> x) {}\n" +
2936
			"}\n" +
2937
			"class B extends A {}\n" +
2938
			"class C extends B implements I {\n" +
2939
			"	void a(C c) {}\n" +
2940
			"	void b(C c) {}\n" +
2941
			"	void b(C[] c) {}\n" +
2942
			"	void c(C c) {}\n" +
2943
			"}\n" +
2944
			"class D extends C {\n" +
2945
			"    void test() {\n" +
2946
			"        a(new C());\n" +
2947
			"        a(new D());\n" +
2948
			"        b(new C());\n" + // ambiguous b(I<?>) in A and b(C) in C match
2949
			"        b(new D());\n" + // ambiguous b(I<?>) in A and b(C) in C match
2950
			"        b(new C[0]);\n" + // ambiguous b(I<?>[]) in A and b(C[]) in C match
2951
			"        b(new D[0]);\n" + // ambiguous b(I<?>[]) in A and b(C[]) in C match
2952
			"        c(new C());\n" + // ambiguous <U>c(I<?>) in A and c(C) in C match
2953
			"        c(new D());\n" + // ambiguous <U>c(I<?>) in A and c(C) in C match
2954
			"    }\n" +
2955
			"}\n" +
2956
			"class A2<T> {\n" +
2957
			"	void a(I x) {}\n" +
2958
			"	void b(I<?> x) {}\n" +
2959
			"	<U> void c(I<?> x) {}\n" +
2960
			"	void d(I<T> x) {}\n" +
2961
			"}\n" +
2962
			"class B2 extends A2 {}\n" +
2963
			"class C2 extends B2 implements I {\n" +
2964
			"	void a(C2 c) {}\n" +
2965
			"	void b(C2 c) {}\n" +
2966
			"	void c(C2 c) {}\n" +
2967
			"	void d(C2 c) {}\n" +
2968
			"}\n" +
2969
			"class D2 extends C2 {\n" +
2970
			"    void test() {\n" +
2971
			"        a(new C2());\n" +
2972
			"        a(new D2());\n" +
2973
			"        b(new C2());\n" +
2974
			"        b(new D2());\n" +
2975
			"        c(new C2());\n" +
2976
			"        c(new D2());\n" +
2977
			"        d(new C2());\n" +
2978
			"        d(new D2());\n" +
2979
			"    }\n" +
2980
			"}"
2981
		},
2982
		"----------\n" + 
2983
		"1. WARNING in Y.java (at line 3)\n" + 
2984
		"	void a(I x) {}\n" + 
2985
		"	       ^\n" + 
2986
		"I is a raw type. References to generic type I<T> should be parameterized\n" + 
2987
		"----------\n" + 
2988
		"2. WARNING in Y.java (at line 9)\n" + 
2989
		"	class C extends B implements I {\n" + 
2990
		"	                             ^\n" + 
2991
		"I is a raw type. References to generic type I<T> should be parameterized\n" + 
2992
		"----------\n" + 
2993
		"3. ERROR in Y.java (at line 19)\n" + 
2994
		"	b(new C());\n" + 
2995
		"	^\n" + 
2996
		"The method b(C) is ambiguous for the type D\n" + 
2997
		"----------\n" + 
2998
		"4. ERROR in Y.java (at line 20)\n" + 
2999
		"	b(new D());\n" + 
3000
		"	^\n" + 
3001
		"The method b(C) is ambiguous for the type D\n" + 
3002
		"----------\n" + 
3003
		"5. ERROR in Y.java (at line 21)\n" + 
3004
		"	b(new C[0]);\n" + 
3005
		"	^\n" + 
3006
		"The method b(C[]) is ambiguous for the type D\n" + 
3007
		"----------\n" + 
3008
		"6. ERROR in Y.java (at line 22)\n" + 
3009
		"	b(new D[0]);\n" + 
3010
		"	^\n" + 
3011
		"The method b(C[]) is ambiguous for the type D\n" + 
3012
		"----------\n" + 
3013
		"7. ERROR in Y.java (at line 23)\n" + 
3014
		"	c(new C());\n" + 
3015
		"	^\n" + 
3016
		"The method c(C) is ambiguous for the type D\n" + 
3017
		"----------\n" + 
3018
		"8. ERROR in Y.java (at line 24)\n" + 
3019
		"	c(new D());\n" + 
3020
		"	^\n" + 
3021
		"The method c(C) is ambiguous for the type D\n" + 
3022
		"----------\n" + 
3023
		"9. WARNING in Y.java (at line 28)\n" + 
3024
		"	void a(I x) {}\n" + 
3025
		"	       ^\n" + 
3026
		"I is a raw type. References to generic type I<T> should be parameterized\n" + 
3027
		"----------\n" + 
3028
		"10. WARNING in Y.java (at line 33)\n" + 
3029
		"	class B2 extends A2 {}\n" + 
3030
		"	                 ^^\n" + 
3031
		"A2 is a raw type. References to generic type A2<T> should be parameterized\n" + 
3032
		"----------\n" + 
3033
		"11. WARNING in Y.java (at line 34)\n" + 
3034
		"	class C2 extends B2 implements I {\n" + 
3035
		"	                               ^\n" + 
3036
		"I is a raw type. References to generic type I<T> should be parameterized\n" + 
3037
		"----------\n"
3038
	);
3039
}
2940
}
3040
}

Return to bug 206930