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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-1 / +1 lines)
Lines 489-495 Link Here
489
	} else {
489
	} else {
490
		methodModifiers |= ExtraCompilerModifiers.AccGenericSignature;
490
		methodModifiers |= ExtraCompilerModifiers.AccGenericSignature;
491
		// MethodTypeSignature = ParameterPart(optional) '(' TypeSignatures ')' return_typeSignature ['^' TypeSignature (optional)]
491
		// MethodTypeSignature = ParameterPart(optional) '(' TypeSignatures ')' return_typeSignature ['^' TypeSignature (optional)]
492
		SignatureWrapper wrapper = new SignatureWrapper(methodSignature, true);
492
		SignatureWrapper wrapper = new SignatureWrapper(methodSignature, use15specifics);
493
		if (wrapper.signature[wrapper.start] == '<') {
493
		if (wrapper.signature[wrapper.start] == '<') {
494
			// <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA;
494
			// <A::Ljava/lang/annotation/Annotation;>(Ljava/lang/Class<TA;>;)TA;
495
			// ParameterPart = '<' ParameterSignature(s) '>'
495
			// ParameterPart = '<' ParameterSignature(s) '>'
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-23 / +3 lines)
Lines 504-510 Link Here
504
	/**
504
	/**
505
	 * Internal use only
505
	 * Internal use only
506
	 * Given a method, returns null if arguments cannot be converted to parameters.
506
	 * Given a method, returns null if arguments cannot be converted to parameters.
507
	 * Will answer a subsituted method in case the method was generic and type inference got triggered;
507
	 * Will answer a substituted method in case the method was generic and type inference got triggered;
508
	 * in case the method was originally compatible, then simply answer it back.
508
	 * in case the method was originally compatible, then simply answer it back.
509
	 */
509
	 */
510
	protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) {
510
	protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) {
Lines 524-531 Link Here
524
			if (!isVarArgs || argLength < paramLength - 1)
524
			if (!isVarArgs || argLength < paramLength - 1)
525
				return null; // incompatible
525
				return null; // incompatible
526
526
527
		if (typeVariables != Binding.NO_TYPE_VARIABLES) { // generic method
527
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330435, inference should kick in only at source 1.5+
528
			boolean compliant14 = compilerOptions().complianceLevel < ClassFileConstants.JDK1_5;
528
		if (typeVariables != Binding.NO_TYPE_VARIABLES && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { // generic method
529
			TypeBinding[] newArgs = null;
529
			TypeBinding[] newArgs = null;
530
			for (int i = 0; i < argLength; i++) {
530
			for (int i = 0; i < argLength; i++) {
531
				TypeBinding param = i < paramLength ? parameters[i] : parameters[paramLength - 1];
531
				TypeBinding param = i < paramLength ? parameters[i] : parameters[paramLength - 1];
Lines 535-560 Link Here
535
						System.arraycopy(arguments, 0, newArgs, 0, argLength);
535
						System.arraycopy(arguments, 0, newArgs, 0, argLength);
536
					}
536
					}
537
					newArgs[i] = environment().computeBoxingType(arguments[i]);
537
					newArgs[i] = environment().computeBoxingType(arguments[i]);
538
				} else if (compliant14 && invocationSite instanceof MessageSend
539
						   && param.kind() == Binding.PARAMETERIZED_TYPE && param.erasure().id == TypeIds.T_JavaLangClass
540
						   && ((ParameterizedTypeBinding) param).arguments.length == 1 
541
						   && ((ParameterizedTypeBinding) param).arguments[0] instanceof TypeVariableBinding 
542
						   && arguments[i] instanceof BinaryTypeBinding && arguments[i].erasure().id == TypeIds.T_JavaLangClass) {
543
					/* https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775. Class literals are special in that
544
					   they carry (and are the only expressions that can carry) full parameterization information
545
					   even in 1.4 source code. For inference during method selection/invocation to work properly,
546
					   resolve class literal expression's type to be a parameterized type if in 1.4 we encounter
547
					   a method that expects a parameter of the type Class<>   
548
					 */
549
					if (newArgs == null) {
550
						newArgs = new TypeBinding[argLength];
551
						System.arraycopy(arguments, 0, newArgs, 0, argLength);
552
					}
553
					ClassLiteralAccess classLiteral = (ClassLiteralAccess) ((MessageSend) invocationSite).arguments[i];
554
					// Integer.class --> Class<Integer>, perform boxing of base types (int.class --> Class<Integer>)
555
					// BundleWiring.class --> Class<BundleWiring>
556
					TypeBinding boxedType = boxing(classLiteral.targetType);
557
					newArgs[i] = classLiteral.resolvedType = environment().createParameterizedType(((ParameterizedTypeBinding)param).genericType(), new TypeBinding[]{ boxedType }, null /*not a member*/);
558
				}
538
				}
559
			}
539
			}
560
			if (newArgs != null)
540
			if (newArgs != null)
(-)compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (+4 lines)
Lines 6621-6626 Link Here
6621
		typeParam.sourceEnd);
6621
		typeParam.sourceEnd);
6622
}
6622
}
6623
public void typeMismatchError(TypeBinding actualType, TypeBinding expectedType, ASTNode location, ASTNode expectingLocation) {
6623
public void typeMismatchError(TypeBinding actualType, TypeBinding expectedType, ASTNode location, ASTNode expectingLocation) {
6624
	if (this.options.sourceLevel < ClassFileConstants.JDK1_5) { // don't expose type variable names, complain on erased types
6625
		actualType = actualType.erasure();
6626
		expectedType = expectedType.erasure();
6627
	}
6624
	if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
6628
	if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
6625
		this.handle(
6629
		this.handle(
6626
				IProblem.UndefinedType,
6630
				IProblem.UndefinedType,
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (-1 / +1 lines)
Lines 11902-11908 Link Here
11902
		        "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + 
11902
		        "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + 
11903
		        "	Bundle b = Bundle.adapt(BundleWiring.class);\n" + 
11903
		        "	Bundle b = Bundle.adapt(BundleWiring.class);\n" + 
11904
		        "	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11904
		        "	           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11905
		        "Type mismatch: cannot convert from BundleWiring to Bundle\n" + 
11905
		        "Type mismatch: cannot convert from Object to Bundle\n" + 
11906
		        "----------\n" + 
11906
		        "----------\n" + 
11907
		        "1 problem (1 error)",
11907
		        "1 problem (1 error)",
11908
		        true);
11908
		        true);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+97 lines)
Lines 11316-11319 Link Here
11316
		compilerOptions14,
11316
		compilerOptions14,
11317
		null);
11317
		null);
11318
}
11318
}
11319
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330435 
11320
public void test330435() {
11321
	Map compilerOptions15 = getCompilerOptions();
11322
	compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5);
11323
	compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
11324
	compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
11325
	this.runConformTest(
11326
		new String[] {
11327
			"A.java",
11328
			"public class A {\n" +
11329
			"	public static <T> B<T> asList(T... tab) {\n" + 
11330
			"		return null;\n" + 
11331
			"	}\n" +
11332
			"}",
11333
			"B.java",
11334
			"public interface B<V> {\n" +
11335
			"	<T> T[] toArray(T[] tab);\n" + 
11336
			"}\n",
11337
		},
11338
		"",
11339
		null,
11340
		true,
11341
		null,
11342
		compilerOptions15,
11343
		null);
11344
	    
11345
	Map compilerOptions14 = getCompilerOptions();
11346
	compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2);
11347
	compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
11348
	compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
11349
	compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE);
11350
	this.runNegativeTest(
11351
		new String[] {
11352
			"X.java",
11353
			"public class X {\n" + 
11354
			"	String[] foo(Object[] args) {\n" + 
11355
			"		String[] a = A.asList(args).toArray(new String[0]);\n" + 
11356
			"		return a;\n" + 
11357
			"	}\n" + 
11358
			"}",
11359
		},
11360
		"----------\n" + 
11361
		"1. ERROR in X.java (at line 3)\n" + 
11362
		"	String[] a = A.asList(args).toArray(new String[0]);\n" + 
11363
		"	             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11364
		"Type mismatch: cannot convert from Object[] to String[]\n" + 
11365
		"----------\n",
11366
		null,
11367
		false,
11368
		compilerOptions14);
11369
}
11370
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330264 
11371
public void test330264() {
11372
	Map compilerOptions15 = getCompilerOptions();
11373
	compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5);
11374
	compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
11375
	compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
11376
	this.runConformTest(
11377
		new String[] {
11378
			"BundleContext.java",
11379
			"public interface BundleContext {\n" +
11380
			"    <S> S getService(ServiceReference<S> reference);\n" +
11381
			"}\n",
11382
			"ServiceReference.java",
11383
			"public interface ServiceReference<S> extends Comparable<Object> {}\n"
11384
		},
11385
		"",
11386
		null,
11387
		true,
11388
		null,
11389
		compilerOptions15,
11390
		null);
11391
	    
11392
	Map compilerOptions14 = getCompilerOptions();
11393
	compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2);
11394
	compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
11395
	compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
11396
	compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE);
11397
	this.runNegativeTest(
11398
		new String[] {
11399
			"Activator.java",
11400
			"public class Activator  {\n" +
11401
			"    public void start(BundleContext context, ServiceReference ref) {\n" +
11402
			"        Runnable r = context.getService(ref);\n" +
11403
			"    }\n" +
11404
			"}\n",
11405
		},
11406
		"----------\n" + 
11407
		"1. ERROR in Activator.java (at line 3)\n" + 
11408
		"	Runnable r = context.getService(ref);\n" + 
11409
		"	             ^^^^^^^^^^^^^^^^^^^^^^^\n" + 
11410
		"Type mismatch: cannot convert from Object to Runnable\n" + 
11411
		"----------\n",
11412
		null,
11413
		false,
11414
		compilerOptions14);
11415
}
11319
}
11416
}

Return to bug 330435