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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java (+73 lines)
Lines 2273-2276 Link Here
2273
		""
2273
		""
2274
	);
2274
	);
2275
}
2275
}
2276
2277
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214558
2278
public void test066() {
2279
	this.runNegativeTest(
2280
		new String[] {
2281
			"A.java",
2282
			"import java.util.*;\n" + 
2283
			"public class A {\n" + 
2284
			"	void foo(Collection<Object[]> c) {}\n" +
2285
			"	void foo(Collection<Object[]> c, Object o) {}\n" +
2286
			"	public static void main(String[] args) {\n" +
2287
			"		new B().foo(new ArrayList());\n" +
2288
			"		new B().foo(new ArrayList(), args[0]);\n" +
2289
			"	}\n" +
2290
			"}\n" + 
2291
			"class B extends A {\n" + 
2292
			"	void foo(ArrayList a) {}\n" + 
2293
			"	void foo(ArrayList a, Object o) {}\n" + 
2294
			"}"
2295
		},
2296
		"----------\n" + 
2297
		"1. ERROR in A.java (at line 6)\n" + 
2298
		"	new B().foo(new ArrayList());\n" + 
2299
		"	        ^^^\n" + 
2300
		"The method foo(ArrayList) is ambiguous for the type B\n" + 
2301
		"----------\n" + 
2302
		"2. WARNING in A.java (at line 6)\n" + 
2303
		"	new B().foo(new ArrayList());\n" + 
2304
		"	                ^^^^^^^^^\n" + 
2305
		"ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + 
2306
		"----------\n" + 
2307
		"3. ERROR in A.java (at line 7)\n" + 
2308
		"	new B().foo(new ArrayList(), args[0]);\n" + 
2309
		"	        ^^^\n" + 
2310
		"The method foo(ArrayList, Object) is ambiguous for the type B\n" + 
2311
		"----------\n" + 
2312
		"4. WARNING in A.java (at line 7)\n" + 
2313
		"	new B().foo(new ArrayList(), args[0]);\n" + 
2314
		"	                ^^^^^^^^^\n" + 
2315
		"ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + 
2316
		"----------\n" + 
2317
		"5. WARNING in A.java (at line 11)\n" + 
2318
		"	void foo(ArrayList a) {}\n" + 
2319
		"	         ^^^^^^^^^\n" + 
2320
		"ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + 
2321
		"----------\n" + 
2322
		"6. WARNING in A.java (at line 12)\n" + 
2323
		"	void foo(ArrayList a, Object o) {}\n" + 
2324
		"	         ^^^^^^^^^\n" + 
2325
		"ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" + 
2326
		"----------\n"
2327
	);
2328
}
2329
2330
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214558 - positive case
2331
public void test067() {
2332
	this.runConformTest(
2333
		new String[] {
2334
			"A.java",
2335
			"import java.util.*;\n" + 
2336
			"public class A {\n" + 
2337
			"	void foo(Collection<Object[]> c) {}\n" +
2338
			"	public static void main(String[] args) {\n" +
2339
			"		new B().foo(new ArrayList<Object>());\n" +
2340
			"	}\n" +
2341
			"}\n" + 
2342
			"class B extends A {\n" + 
2343
			"	void foo(ArrayList<Object> a) {System.out.print(1);}\n" + 
2344
			"}"
2345
		},
2346
		"1"
2347
	);
2348
}
2276
}
2349
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-1 / +14 lines)
Lines 766-776 Link Here
766
766
767
	// Internal use only
767
	// Internal use only
768
	public MethodBinding findExactMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
768
	public MethodBinding findExactMethod(ReferenceBinding receiverType, char[] selector, TypeBinding[] argumentTypes, InvocationSite invocationSite) {
769
		boolean checkArgsForRawTypes = false;
770
		switch (argumentTypes.length) {
771
			case 0 : break;
772
			case 1 :
773
			case 2 :
774
				checkArgsForRawTypes = compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5;
775
			default :
776
				if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5)
777
					return null; // skip find exact match since its less likely to find a match & raw type check is not worth it
778
		}
769
		CompilationUnitScope unitScope = compilationUnitScope();
779
		CompilationUnitScope unitScope = compilationUnitScope();
770
		unitScope.recordTypeReferences(argumentTypes);
780
		unitScope.recordTypeReferences(argumentTypes);
771
		MethodBinding exactMethod = receiverType.getExactMethod(selector, argumentTypes, unitScope);
781
		MethodBinding exactMethod = receiverType.getExactMethod(selector, argumentTypes, unitScope);
772
		if (exactMethod != null && exactMethod.typeVariables == Binding.NO_TYPE_VARIABLES && !exactMethod.isBridge()) {
782
		if (exactMethod != null && exactMethod.typeVariables == Binding.NO_TYPE_VARIABLES && !exactMethod.isBridge()) {
773
			
783
			if (checkArgsForRawTypes)
784
				for (int i = argumentTypes.length; --i >= 0;)
785
					if (argumentTypes[i].isRawType())
786
						return null;
774
			// must find both methods for this case: <S extends A> void foo() {}  and  <N extends B> N foo() { return null; }
787
			// must find both methods for this case: <S extends A> void foo() {}  and  <N extends B> N foo() { return null; }
775
			// or find an inherited method when the exact match is to a bridge method
788
			// or find an inherited method when the exact match is to a bridge method
776
			unitScope.recordTypeReferences(exactMethod.thrownExceptions);
789
			unitScope.recordTypeReferences(exactMethod.thrownExceptions);

Return to bug 214558