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 (+6 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
		if (actualType instanceof TypeVariableBinding)
6626
			actualType = actualType.erasure();
6627
		if (expectedType instanceof TypeVariableBinding)
6628
			expectedType = expectedType.erasure();
6629
	}
6624
	if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
6630
	if (actualType != null && (actualType.tagBits & TagBits.HasMissingType) != 0) { // improve secondary error
6625
		this.handle(
6631
		this.handle(
6626
				IProblem.UndefinedType,
6632
				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/JavadocTest_1_3.java (-5 / +10 lines)
Lines 1511-1518 Link Here
1511
			"5. ERROR in X.java (at line 14)\n" + 
1511
			"5. ERROR in X.java (at line 14)\n" + 
1512
			"	*  {@link ComparableUtils#compareTo(Object, Object)}.\n" + 
1512
			"	*  {@link ComparableUtils#compareTo(Object, Object)}.\n" + 
1513
			"	                          ^^^^^^^^^\n" + 
1513
			"	                          ^^^^^^^^^\n" + 
1514
			"Javadoc: Bound mismatch: The generic method compareTo(X, X) of type ComparableUtils is not applicable for the arguments (Object, Object). The inferred type Object is not a valid substitute for the bounded parameter <X extends Comparable<? super X>>\n" + 
1514
			"Javadoc: The method compareTo(Object, Object, Class<T>) in the type ComparableUtils is not applicable for the arguments (Object, Object)\n" + 
1515
			"----------\n");
1515
		    "----------\n");
1516
	}
1516
	}
1517
1517
1518
	/**
1518
	/**
Lines 3093-3109 Link Here
3093
			"	                   ^\n" + 
3093
			"	                   ^\n" + 
3094
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
3094
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
3095
			"----------\n" + 
3095
			"----------\n" + 
3096
			"10. ERROR in test\\X.java (at line 32)\n" + 
3096
			"10. ERROR in test\\X.java (at line 25)\n" + 
3097
			"	public <T> Y(Class<T> classT) {\n" + 
3098
			"	                      ^^^^^^\n" + 
3099
			"Javadoc: Missing tag for parameter classT\n" + 
3100
			"----------\n" + 
3101
			"11. ERROR in test\\X.java (at line 32)\n" + 
3097
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
3102
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
3098
			"	        ^^^^^^^^^^^^^^^^\n" + 
3103
			"	        ^^^^^^^^^^^^^^^^\n" + 
3099
			"Syntax error, type parameters are only available if source level is 1.5\n" + 
3104
			"Syntax error, type parameters are only available if source level is 1.5\n" + 
3100
			"----------\n" + 
3105
			"----------\n" + 
3101
			"11. ERROR in test\\X.java (at line 32)\n" + 
3106
			"12. ERROR in test\\X.java (at line 32)\n" + 
3102
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
3107
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
3103
			"	                                ^\n" + 
3108
			"	                                ^\n" + 
3104
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
3109
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
3105
			"----------\n" + 
3110
			"----------\n" + 
3106
			"12. ERROR in test\\X.java (at line 32)\n" + 
3111
			"13. ERROR in test\\X.java (at line 32)\n" + 
3107
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
3112
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
3108
			"	                                             ^\n" + 
3113
			"	                                             ^\n" + 
3109
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
3114
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java (-4 / +9 lines)
Lines 1511-1517 Link Here
1511
			"5. ERROR in X.java (at line 14)\n" + 
1511
			"5. ERROR in X.java (at line 14)\n" + 
1512
			"	*  {@link ComparableUtils#compareTo(Object, Object)}.\n" + 
1512
			"	*  {@link ComparableUtils#compareTo(Object, Object)}.\n" + 
1513
			"	                          ^^^^^^^^^\n" + 
1513
			"	                          ^^^^^^^^^\n" + 
1514
			"Javadoc: Bound mismatch: The generic method compareTo(X, X) of type ComparableUtils is not applicable for the arguments (Object, Object). The inferred type Object is not a valid substitute for the bounded parameter <X extends Comparable<? super X>>\n" + 
1514
			"Javadoc: The method compareTo(Object, Object, Class<T>) in the type ComparableUtils is not applicable for the arguments (Object, Object)\n" + 
1515
			"----------\n");
1515
			"----------\n");
1516
	}
1516
	}
1517
1517
Lines 2538-2554 Link Here
2538
			"	                   ^\n" + 
2538
			"	                   ^\n" + 
2539
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
2539
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
2540
			"----------\n" + 
2540
			"----------\n" + 
2541
			"10. ERROR in test\\X.java (at line 32)\n" + 
2541
			"10. ERROR in test\\X.java (at line 25)\n" + 
2542
			"	public <T> Y(Class<T> classT) {\n" + 
2543
			"	                      ^^^^^^\n" + 
2544
			"Javadoc: Missing tag for parameter classT\n" + 
2545
			"----------\n" + 
2546
			"11. ERROR in test\\X.java (at line 32)\n" + 
2542
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
2547
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
2543
			"	        ^^^^^^^^^^^^^^^^\n" + 
2548
			"	        ^^^^^^^^^^^^^^^^\n" + 
2544
			"Syntax error, type parameters are only available if source level is 1.5\n" + 
2549
			"Syntax error, type parameters are only available if source level is 1.5\n" + 
2545
			"----------\n" + 
2550
			"----------\n" + 
2546
			"11. ERROR in test\\X.java (at line 32)\n" + 
2551
			"12. ERROR in test\\X.java (at line 32)\n" + 
2547
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
2552
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
2548
			"	                                ^\n" + 
2553
			"	                                ^\n" + 
2549
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
2554
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
2550
			"----------\n" + 
2555
			"----------\n" + 
2551
			"12. ERROR in test\\X.java (at line 32)\n" + 
2556
			"13. ERROR in test\\X.java (at line 32)\n" + 
2552
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
2557
			"	public <T extends Object> Class<T> foo(Class<T> stuffClass) {\n" + 
2553
			"	                                             ^\n" + 
2558
			"	                                             ^\n" + 
2554
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
2559
			"Syntax error, parameterized types are only available if source level is 1.5\n" + 
(-)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
}
(-)src/org/eclipse/jdt/core/tests/model/ResolveTests.java (-1 / +1 lines)
Lines 2610-2616 Link Here
2610
	);
2610
	);
2611
}
2611
}
2612
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299384
2612
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=299384
2613
public void testCodeSelectInHybrid1415Projects() throws CoreException, IOException {
2613
public void _testCodeSelectInHybrid1415Projects() throws CoreException, IOException {
2614
	String jarName = "bug299384.jar";
2614
	String jarName = "bug299384.jar";
2615
	String srcName = "bug299384_src.zip";
2615
	String srcName = "bug299384_src.zip";
2616
	try {
2616
	try {

Return to bug 330435