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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (+34 lines)
Lines 7510-7513 Link Here
7510
		"The method bar(String, String) of type X is not generic; it cannot be parameterized with arguments <String>\n" + 
7510
		"The method bar(String, String) of type X is not generic; it cannot be parameterized with arguments <String>\n" + 
7511
		"----------\n");
7511
		"----------\n");
7512
}
7512
}
7513
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174445
7514
public void test127() {
7515
	this.runNegativeTest(
7516
		new String[] {
7517
			"X.java",
7518
			"public class X {\n" + 
7519
			"  enum Enum1 {\n" + 
7520
			"    value;\n" + 
7521
			"  }\n" + 
7522
			"  enum Enum2 {\n" + 
7523
			"    value;\n" + 
7524
			"  }\n" + 
7525
			"  static abstract class A<T> {\n" + 
7526
			"    abstract <U extends T> U foo();\n" + 
7527
			"  }\n" + 
7528
			"  static class B extends A<Enum<?>> {\n" + 
7529
			"    @Override\n" + 
7530
			"    Enum<?> foo() {\n" + 
7531
			"      return Enum1.value;\n" + 
7532
			"    }  \n" + 
7533
			"  }\n" + 
7534
			"  public static void main(String[] args) {\n" + 
7535
			"    A<Enum<?>> a = new B();\n" + 
7536
			"    Enum2 value = a.foo();\n" + 
7537
			"  }\n" + 
7538
			"}"
7539
		},
7540
		"----------\n" + 
7541
		"1. WARNING in X.java (at line 13)\n" + 
7542
		"	Enum<?> foo() {\n" + 
7543
		"	^^^^\n" + 
7544
		"Type safety: The return type Enum<?> for foo() from the type X.B needs unchecked conversion to conform to U from the type X.A<T>\n" + 
7545
		"----------\n");
7546
}
7513
}
7547
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-4 / +3 lines)
Lines 134-142 Link Here
134
	if (originalInherited.returnType != currentMethod.returnType) {
134
	if (originalInherited.returnType != currentMethod.returnType) {
135
//		if (currentMethod.returnType.needsUncheckedConversion(inheritedMethod.returnType)) {
135
//		if (currentMethod.returnType.needsUncheckedConversion(inheritedMethod.returnType)) {
136
//			problemReporter(currentMethod).unsafeReturnTypeOverride(currentMethod, originalInherited, this.type);
136
//			problemReporter(currentMethod).unsafeReturnTypeOverride(currentMethod, originalInherited, this.type);
137
		if (inheritedMethod.returnType.leafComponentType().isParameterizedType()) {
137
		if (inheritedMethod.returnType.leafComponentType().isParameterizedType() && currentMethod.returnType.leafComponentType().isRawType()) {
138
			if (currentMethod.returnType.leafComponentType().isRawType())
138
			problemReporter(currentMethod).unsafeReturnTypeOverride(currentMethod, originalInherited, this.type);
139
				problemReporter(currentMethod).unsafeReturnTypeOverride(currentMethod, originalInherited, this.type);
140
		} else if (inheritedMethod.hasSubstitutedReturnType() && originalInherited.returnType.leafComponentType().isTypeVariable()) {
139
		} else if (inheritedMethod.hasSubstitutedReturnType() && originalInherited.returnType.leafComponentType().isTypeVariable()) {
141
			if (((TypeVariableBinding) originalInherited.returnType.leafComponentType()).declaringElement == originalInherited) { // see 81618 - type variable from inherited method
140
			if (((TypeVariableBinding) originalInherited.returnType.leafComponentType()).declaringElement == originalInherited) { // see 81618 - type variable from inherited method
142
				TypeBinding currentReturnType = currentMethod.returnType.leafComponentType();
141
				TypeBinding currentReturnType = currentMethod.returnType.leafComponentType();
Lines 527-533 Link Here
527
	int inheritedLength = inheritedTypeVariables.length;
526
	int inheritedLength = inheritedTypeVariables.length;
528
	TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
527
	TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
529
	int length = typeVariables.length;
528
	int length = typeVariables.length;
530
	if (length > 0 && inheritedLength != length) return inheritedMethod;
529
	if (length > 0 && inheritedLength != length) return inheritedMethod; // no match JLS 8.4.2
531
	TypeBinding[] arguments = new TypeBinding[inheritedLength];
530
	TypeBinding[] arguments = new TypeBinding[inheritedLength];
532
	if (inheritedLength <= length) {
531
	if (inheritedLength <= length) {
533
		System.arraycopy(typeVariables, 0, arguments, 0, inheritedLength);
532
		System.arraycopy(typeVariables, 0, arguments, 0, inheritedLength);

Return to bug 174445