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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-12 / +9 lines)
Lines 533-557 Link Here
533
		((BinaryTypeBinding) inheritedMethod.declaringClass).resolveTypesFor(inheritedMethod);
533
		((BinaryTypeBinding) inheritedMethod.declaringClass).resolveTypesFor(inheritedMethod);
534
534
535
	TypeVariableBinding[] inheritedTypeVariables = inheritedMethod.typeVariables;
535
	TypeVariableBinding[] inheritedTypeVariables = inheritedMethod.typeVariables;
536
	if (inheritedTypeVariables == Binding.NO_TYPE_VARIABLES) return inheritedMethod;
537
	int inheritedLength = inheritedTypeVariables.length;
536
	int inheritedLength = inheritedTypeVariables.length;
537
	if (inheritedLength == 0) return inheritedMethod; // no substitution needed
538
	TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
538
	TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
539
	int length = typeVariables.length;
539
	int length = typeVariables.length;
540
	if (length > 0 && inheritedLength != length) return inheritedMethod; // no match JLS 8.4.2
540
	if (length == 0)
541
	TypeBinding[] arguments = new TypeBinding[inheritedLength];
541
		return inheritedMethod.asRawMethod(this.environment);
542
	if (inheritedLength <= length) {
542
	if (length != inheritedLength)
543
		System.arraycopy(typeVariables, 0, arguments, 0, inheritedLength);
543
		return inheritedMethod; // no match JLS 8.4.2
544
	} else {
545
		System.arraycopy(typeVariables, 0, arguments, 0, length);
546
		for (int i = length; i < inheritedLength; i++)
547
			arguments[i] = inheritedTypeVariables[i].upperBound();
548
	}
549
	ParameterizedGenericMethodBinding substitute =
550
		this.environment.createParameterizedGenericMethod(inheritedMethod, arguments);
551
544
552
	// interface I { <T> void foo(T t); }
545
	// interface I { <T> void foo(T t); }
553
	// class X implements I { public <T extends I> void foo(T t) {} }
546
	// class X implements I { public <T extends I> void foo(T t) {} }
554
	// for the above case, we do not want to answer the substitute method since its not a match
547
	// for the above case, we do not want to answer the substitute method since its not a match
548
	TypeBinding[] arguments = new TypeBinding[length];
549
	System.arraycopy(typeVariables, 0, arguments, 0, length);
550
	ParameterizedGenericMethodBinding substitute =
551
		this.environment.createParameterizedGenericMethod(inheritedMethod, arguments);
555
	for (int i = 0; i < inheritedLength; i++) {
552
	for (int i = 0; i < inheritedLength; i++) {
556
		TypeVariableBinding inheritedTypeVariable = inheritedTypeVariables[i];
553
		TypeVariableBinding inheritedTypeVariable = inheritedTypeVariables[i];
557
		TypeBinding argument = arguments[i];
554
		TypeBinding argument = arguments[i];
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-3 / +57 lines)
Lines 7708-7714 Link Here
7708
			"}"
7708
			"}"
7709
		},
7709
		},
7710
		"----------\n" + 
7710
		"----------\n" + 
7711
		"1. WARNING in X.java (at line 10)\n" + 
7711
		"1. WARNING in X.java (at line 3)\n" +
7712
		"	public A foo(Number n) { return null; }\n" +
7713
		"	       ^\n" +
7714
		"Type safety: The return type A for foo(Number) from the type X2 needs unchecked conversion to conform to T from the type I\n" +
7715
		"----------\n" +
7716
		"2. WARNING in X.java (at line 10)\n" + 
7712
		"	A foo(Number n);\n" + 
7717
		"	A foo(Number n);\n" + 
7713
		"	^\n" + 
7718
		"	^\n" + 
7714
		"Type safety: The return type A for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + 
7719
		"Type safety: The return type A for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + 
Lines 7792-7798 Link Here
7792
		"1. WARNING in X.java (at line 6)\n" + 
7797
		"1. WARNING in X.java (at line 6)\n" + 
7793
		"	A<XX> foo(Number n);\n" + 
7798
		"	A<XX> foo(Number n);\n" + 
7794
		"	^\n" + 
7799
		"	^\n" + 
7795
		"Type safety: The return type A<XX> for foo(Number) from the type J needs unchecked conversion to conform to A<T> from the type I\n" + 
7800
		"Type safety: The return type A<XX> for foo(Number) from the type J needs unchecked conversion to conform to A<Exception&Cloneable> from the type I\n" + 
7796
		"----------\n"
7801
		"----------\n"
7797
	);
7802
	);
7798
}
7803
}
Lines 7817-7823 Link Here
7817
			"}"
7822
			"}"
7818
		},
7823
		},
7819
		"----------\n" + 
7824
		"----------\n" + 
7820
		"1. WARNING in X.java (at line 9)\n" + 
7825
		"1. WARNING in X.java (at line 3)\n" +
7826
		"	public XX foo(Number n) { return null; }\n" +
7827
		"	       ^^\n" +
7828
		"Type safety: The return type XX for foo(Number) from the type X needs unchecked conversion to conform to T from the type I\n" +
7829
		"----------\n" +
7830
		"2. WARNING in X.java (at line 9)\n" +
7821
		"	XX foo(Number n);\n" + 
7831
		"	XX foo(Number n);\n" + 
7822
		"	^^\n" + 
7832
		"	^^\n" + 
7823
		"Type safety: The return type XX for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + 
7833
		"Type safety: The return type XX for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + 
Lines 8904-8907 Link Here
8904
			""
8914
			""
8905
		);
8915
		);
8906
}
8916
}
8917
8918
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262208
8919
public void test183() {
8920
	this.runNegativeTest(
8921
		new String[] {
8922
			"X.java",
8923
			"class XX {\n" +
8924
			"	<T extends C, S extends G<T>> void a(S gC) {}\n" +
8925
			"	<T extends C, S extends G<T>> void b(T c) {}\n" +
8926
			"	<T extends C> void c(G<T> gC) {}\n" +
8927
			"	<T extends C, S extends G<T>> void d(S gC) {}\n" +
8928
			"}\n" +
8929
			"class X extends XX {\n" +
8930
			"	@Override void a(G g) {}\n" +
8931
			"	@Override void b(C c) {}\n" +
8932
			"	@Override void c(G g) {}\n" +
8933
			"	@Override <T extends C, S extends G<C>> void d(S gc) {}\n" +
8934
			"}\n" +
8935
			"class C {}\n" +
8936
			"class G<T2> {}"
8937
		},
8938
		"----------\n" + 
8939
		"1. WARNING in X.java (at line 8)\n" + 
8940
		"	@Override void a(G g) {}\n" + 
8941
		"	                 ^\n" + 
8942
		"G is a raw type. References to generic type G<T2> should be parameterized\n" + 
8943
		"----------\n" + 
8944
		"2. WARNING in X.java (at line 10)\n" + 
8945
		"	@Override void c(G g) {}\n" + 
8946
		"	                 ^\n" + 
8947
		"G is a raw type. References to generic type G<T2> should be parameterized\n" + 
8948
		"----------\n" + 
8949
		"3. ERROR in X.java (at line 11)\n" + 
8950
		"	@Override <T extends C, S extends G<C>> void d(S gc) {}\n" + 
8951
		"	                                             ^^^^^^^\n" + 
8952
		"Name clash: The method d(S) of type X has the same erasure as d(S) of type XX but does not override it\n" + 
8953
		"----------\n" + 
8954
		"4. ERROR in X.java (at line 11)\n" + 
8955
		"	@Override <T extends C, S extends G<C>> void d(S gc) {}\n" + 
8956
		"	                                             ^^^^^^^\n" + 
8957
		mustOverrideMessage("d(S)", "X") + 
8958
		"----------\n"
8959
	);
8960
}
8907
}
8961
}

Return to bug 262208