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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-4 / +58 lines)
Lines 7728-7734 Link Here
7728
			"}"
7728
			"}"
7729
		},
7729
		},
7730
		"----------\n" +
7730
		"----------\n" +
7731
		"1. WARNING in X.java (at line 10)\n" +
7731
		"1. WARNING in X.java (at line 3)\n" +
7732
		"	public A foo(Number n) { return null; }\n" +
7733
		"	       ^\n" +
7734
		"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" +
7735
		"----------\n" +
7736
		"2. WARNING in X.java (at line 10)\n" +
7732
		"	A foo(Number n);\n" +
7737
		"	A foo(Number n);\n" +
7733
		"	^\n" +
7738
		"	^\n" +
7734
		"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" +
7739
		"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 7779-7785 Link Here
7779
			"  XX foo(Number n);\n" +
7784
			"  XX foo(Number n);\n" +
7780
			"}\n" +
7785
			"}\n" +
7781
			"class Z { }\n" +
7786
			"class Z { }\n" +
7782
			"class Y <U> extends Z { }" +
7787
			"class Y <U> extends Z { }\n" +
7783
			"abstract class XX extends Y<XX> implements Cloneable {}"
7788
			"abstract class XX extends Y<XX> implements Cloneable {}"
7784
		},
7789
		},
7785
		"----------\n" +
7790
		"----------\n" +
Lines 7812-7818 Link Here
7812
		"1. WARNING in X.java (at line 6)\n" +
7817
		"1. WARNING in X.java (at line 6)\n" +
7813
		"	A<XX> foo(Number n);\n" +
7818
		"	A<XX> foo(Number n);\n" +
7814
		"	^\n" +
7819
		"	^\n" +
7815
		"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" +
7820
		"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" + 
7816
		"----------\n"
7821
		"----------\n"
7817
	);
7822
	);
7818
}
7823
}
Lines 7837-7843 Link Here
7837
			"}"
7842
			"}"
7838
		},
7843
		},
7839
		"----------\n" +
7844
		"----------\n" +
7840
		"1. WARNING in X.java (at line 9)\n" +
7845
		"1. WARNING in X.java (at line 3)\n" +
7846
		"	public XX foo(Number n) { return null; }\n" +
7847
		"	       ^^\n" +
7848
		"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" +
7849
		"----------\n" +
7850
		"2. WARNING in X.java (at line 9)\n" +
7841
		"	XX foo(Number n);\n" +
7851
		"	XX foo(Number n);\n" +
7842
		"	^^\n" +
7852
		"	^^\n" +
7843
		"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" +
7853
		"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 9329-9332 Link Here
9329
		false
9339
		false
9330
	);
9340
	);
9331
}
9341
}
9342
9343
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262208
9344
public void test183() {
9345
	this.runNegativeTest(
9346
		new String[] {
9347
			"X.java",
9348
			"class XX {\n" +
9349
			"	<T extends C, S extends G<T>> void a(S gC) {}\n" +
9350
			"	<T extends C, S extends G<T>> void b(T c) {}\n" +
9351
			"	<T extends C> void c(G<T> gC) {}\n" +
9352
			"	<T extends C, S extends G<T>> void d(S gC) {}\n" +
9353
			"}\n" +
9354
			"class X extends XX {\n" +
9355
			"	@Override void a(G g) {}\n" +
9356
			"	@Override void b(C c) {}\n" +
9357
			"	@Override void c(G g) {}\n" +
9358
			"	@Override <T extends C, S extends G<C>> void d(S gc) {}\n" +
9359
			"}\n" +
9360
			"class C {}\n" +
9361
			"class G<T2> {}"
9362
		},
9363
		"----------\n" + 
9364
		"1. WARNING in X.java (at line 8)\n" + 
9365
		"	@Override void a(G g) {}\n" + 
9366
		"	                 ^\n" + 
9367
		"G is a raw type. References to generic type G<T2> should be parameterized\n" + 
9368
		"----------\n" + 
9369
		"2. WARNING in X.java (at line 10)\n" + 
9370
		"	@Override void c(G g) {}\n" + 
9371
		"	                 ^\n" + 
9372
		"G is a raw type. References to generic type G<T2> should be parameterized\n" + 
9373
		"----------\n" + 
9374
		"3. ERROR in X.java (at line 11)\n" + 
9375
		"	@Override <T extends C, S extends G<C>> void d(S gc) {}\n" + 
9376
		"	                                             ^^^^^^^\n" + 
9377
		"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" + 
9378
		"----------\n" + 
9379
		"4. ERROR in X.java (at line 11)\n" + 
9380
		"	@Override <T extends C, S extends G<C>> void d(S gc) {}\n" + 
9381
		"	                                             ^^^^^^^\n" + 
9382
		mustOverrideMessage("d(S)", "X") + 
9383
		"----------\n"
9384
	);
9385
}
9332
}
9386
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-13 / +10 lines)
Lines 516-540 Link Here
516
		((BinaryTypeBinding) inheritedMethod.declaringClass).resolveTypesFor(inheritedMethod);
516
		((BinaryTypeBinding) inheritedMethod.declaringClass).resolveTypesFor(inheritedMethod);
517
517
518
	TypeVariableBinding[] inheritedTypeVariables = inheritedMethod.typeVariables;
518
	TypeVariableBinding[] inheritedTypeVariables = inheritedMethod.typeVariables;
519
	if (inheritedTypeVariables == Binding.NO_TYPE_VARIABLES) return inheritedMethod;
520
	int inheritedLength = inheritedTypeVariables.length;
519
	int inheritedLength = inheritedTypeVariables.length;
520
	if (inheritedLength == 0) return inheritedMethod; // no substitution needed
521
	TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
521
	TypeVariableBinding[] typeVariables = currentMethod.typeVariables;
522
	int length = typeVariables.length;
522
	int length = typeVariables.length;
523
	if (length > 0 && inheritedLength != length) return inheritedMethod; // no match JLS 8.4.2
523
	if (length == 0)
524
	TypeBinding[] arguments = new TypeBinding[inheritedLength];
524
		return inheritedMethod.asRawMethod(this.environment);
525
	if (inheritedLength <= length) {
525
	if (length != inheritedLength)
526
		System.arraycopy(typeVariables, 0, arguments, 0, inheritedLength);
526
		return inheritedMethod; // no match JLS 8.4.2
527
	} else {
528
		System.arraycopy(typeVariables, 0, arguments, 0, length);
529
		for (int i = length; i < inheritedLength; i++)
530
			arguments[i] = inheritedTypeVariables[i].upperBound();
531
	}
532
	ParameterizedGenericMethodBinding substitute =
533
		this.environment.createParameterizedGenericMethod(inheritedMethod, arguments);
534
527
535
	// interface I { <T> void foo(T t); }
528
	// interface I { <T> void foo(T t); }
536
	// class X implements I { public <T extends I> void foo(T t) {} }
529
	// class X implements I { public <T extends I> void foo(T t) {} }
537
	// for the above case, we do not want to answer the substitute method since its not a match
530
	// for the above case, we do not want to answer the substitute method since its not a match
531
	TypeBinding[] arguments = new TypeBinding[length];
532
	System.arraycopy(typeVariables, 0, arguments, 0, length);
533
	ParameterizedGenericMethodBinding substitute =
534
		this.environment.createParameterizedGenericMethod(inheritedMethod, arguments);
538
	for (int i = 0; i < inheritedLength; i++) {
535
	for (int i = 0; i < inheritedLength; i++) {
539
		TypeVariableBinding inheritedTypeVariable = inheritedTypeVariables[i];
536
		TypeVariableBinding inheritedTypeVariable = inheritedTypeVariables[i];
540
		TypeBinding argument = arguments[i];
537
		TypeBinding argument = arguments[i];
Lines 562-568 Link Here
562
				return inheritedMethod; // not a match
559
				return inheritedMethod; // not a match
563
			}
560
			}
564
		} else if (inheritedTypeVariable.boundCheck(substitute, argument) != TypeConstants.OK) {
561
		} else if (inheritedTypeVariable.boundCheck(substitute, argument) != TypeConstants.OK) {
565
	    		return inheritedMethod;
562
	    	return inheritedMethod;
566
		}
563
		}
567
	}
564
	}
568
   return substitute;
565
   return substitute;

Return to bug 262208