Lines 7544-7547
Link Here
|
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" + |
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"); |
7545 |
"----------\n"); |
7546 |
} |
7546 |
} |
|
|
7547 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7548 |
public void test128() { |
7549 |
this.runNegativeTest( |
7550 |
new String[] { |
7551 |
"X.java", |
7552 |
"interface I<U, V> {\n" + |
7553 |
" U foo(Object o, V v);\n" + |
7554 |
"}\n" + |
7555 |
"public class X<U, V> implements I<U, V> {\n" + |
7556 |
" public Object foo(Object o, Object v) { return null; }\n" + |
7557 |
"}\n" |
7558 |
}, |
7559 |
"----------\n" + |
7560 |
"1. WARNING in X.java (at line 5)\n" + |
7561 |
" public Object foo(Object o, Object v) { return null; }\n" + |
7562 |
" ^^^^^^\n" + |
7563 |
"Type safety: The return type Object for foo(Object, Object) from the type X<U,V> needs unchecked conversion to conform to U from the type I<U,V>\n" + |
7564 |
"----------\n" |
7565 |
); |
7566 |
} |
7567 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7568 |
// variant - Object is not a subtype of Z |
7569 |
public void test129() { |
7570 |
this.runNegativeTest( |
7571 |
new String[] { |
7572 |
"X.java", |
7573 |
"interface I<U, V> {\n" + |
7574 |
" U foo(Object o, V v);\n" + |
7575 |
"}\n" + |
7576 |
"public class X<U extends Z, V> implements I<U, V> {\n" + |
7577 |
" public Object foo(Object o, Object v) { return null; }\n" + |
7578 |
"}\n" + |
7579 |
"class Z {}" |
7580 |
}, |
7581 |
"----------\n" + |
7582 |
"1. ERROR in X.java (at line 5)\n" + |
7583 |
" public Object foo(Object o, Object v) { return null; }\n" + |
7584 |
" ^^^^^^\n" + |
7585 |
"The return type is incompatible with I<U,V>.foo(Object, V)\n" + |
7586 |
"----------\n" |
7587 |
); |
7588 |
} |
7589 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7590 |
// ** variant - Z<Object> is not a subtype of Z<U>, and |Z<U>| = Z, not Z<Object> |
7591 |
public void test130() { |
7592 |
this.runNegativeTest( |
7593 |
new String[] { |
7594 |
"X.java", |
7595 |
"interface I<U, V> {\n" + |
7596 |
" Z<U> foo(Object o, V v);\n" + |
7597 |
"}\n" + |
7598 |
"public class X<U, V> implements I<U, V> {\n" + |
7599 |
" public Z<Object> foo(Object o, Object v) { return null; }\n" + |
7600 |
"}\n" + |
7601 |
"class Z<T> {}" |
7602 |
}, |
7603 |
"----------\n" + |
7604 |
"1. ERROR in X.java (at line 5)\n" + |
7605 |
" public Z<Object> foo(Object o, Object v) { return null; }\n" + |
7606 |
" ^^^^^^^^^\n" + |
7607 |
"The return type is incompatible with I<U,V>.foo(Object, V)\n" + |
7608 |
"----------\n" |
7609 |
); |
7610 |
} |
7611 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7612 |
// variant - two interfaces |
7613 |
public void test131() { |
7614 |
this.runNegativeTest( |
7615 |
new String[] { |
7616 |
"X.java", |
7617 |
"interface I<U, V> {\n" + |
7618 |
" U foo();\n" + |
7619 |
" U foo(Object o, V v);\n" + |
7620 |
"}\n" + |
7621 |
"interface X<U, V> extends I<U, V> {\n" + |
7622 |
" Object foo();\n" + |
7623 |
" Object foo(Object o, Object v);\n" + |
7624 |
"}\n" |
7625 |
}, |
7626 |
"----------\n" + |
7627 |
"1. ERROR in X.java (at line 6)\n" + |
7628 |
" Object foo();\n" + |
7629 |
" ^^^^^^\n" + |
7630 |
"The return type is incompatible with I<U,V>.foo()\n" + |
7631 |
"----------\n" + |
7632 |
"2. WARNING in X.java (at line 7)\n" + |
7633 |
" Object foo(Object o, Object v);\n" + |
7634 |
" ^^^^^^\n" + |
7635 |
"Type safety: The return type Object for foo(Object, Object) from the type X<U,V> needs unchecked conversion to conform to U from the type I<U,V>\n" + |
7636 |
"----------\n" |
7637 |
); |
7638 |
} |
7639 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7640 |
// variant - type identity vs type equivalence |
7641 |
public void test132() { |
7642 |
this.runNegativeTest( |
7643 |
new String[] { |
7644 |
"X.java", |
7645 |
"interface I<U> {\n" + |
7646 |
" U foo(I<?> p);\n" + |
7647 |
" U foo2(I<? extends Object> p);\n" + |
7648 |
"}\n" + |
7649 |
"public class X<U> implements I<U> {\n" + |
7650 |
" public Object foo(I<? extends Object> p) { return null; }\n" + |
7651 |
" public Object foo2(I<?> p) { return null; }\n" + |
7652 |
"}\n" |
7653 |
}, |
7654 |
"----------\n" + |
7655 |
"1. ERROR in X.java (at line 6)\n" + |
7656 |
" public Object foo(I<? extends Object> p) { return null; }\n" + |
7657 |
" ^^^^^^\n" + |
7658 |
"The return type is incompatible with I<U>.foo(I<?>)\n" + |
7659 |
"----------\n" + |
7660 |
"2. ERROR in X.java (at line 7)\n" + |
7661 |
" public Object foo2(I<?> p) { return null; }\n" + |
7662 |
" ^^^^^^\n" + |
7663 |
"The return type is incompatible with I<U>.foo2(I<? extends Object>)\n" + |
7664 |
"----------\n" |
7665 |
); |
7666 |
} |
7667 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7668 |
// variant - if we detect a return type incompatibility, then skip any @Override errors |
7669 |
public void test133() { |
7670 |
this.runNegativeTest( |
7671 |
new String[] { |
7672 |
"A.java", |
7673 |
"class A<U> {\n" + |
7674 |
" U foo() { return null; }\n" + |
7675 |
" U foo(U one) { return null; }\n" + |
7676 |
" U foo(U one, U two) { return null; }\n" + |
7677 |
"}\n" + |
7678 |
"class B<U> extends A<U> {\n" + |
7679 |
" @Override // does not override error\n" + |
7680 |
" Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + |
7681 |
" @Override // does not override error\n" + |
7682 |
" Object foo(Object one) { return null; } // unchecked conversion warning\n" + |
7683 |
" @Override // does not override error\n" + |
7684 |
" Object foo(Object one, U two) { return null; }\n" + |
7685 |
"}\n" + |
7686 |
"class C<U> extends A<U> {\n" + |
7687 |
" @Override // does not override error\n" + |
7688 |
" Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + |
7689 |
" @Override // does not override error\n" + |
7690 |
" Object foo(U one, U two) { return null; } // cannot override foo(U), incompatible return type error\n" + |
7691 |
"}" |
7692 |
}, |
7693 |
"----------\n" + |
7694 |
"1. ERROR in A.java (at line 8)\n" + |
7695 |
" Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + |
7696 |
" ^^^^^^\n" + |
7697 |
"The return type is incompatible with A<U>.foo()\n" + |
7698 |
"----------\n" + |
7699 |
"2. WARNING in A.java (at line 10)\n" + |
7700 |
" Object foo(Object one) { return null; } // unchecked conversion warning\n" + |
7701 |
" ^^^^^^\n" + |
7702 |
"Type safety: The return type Object for foo(Object) from the type B<U> needs unchecked conversion to conform to U from the type A<U>\n" + |
7703 |
"----------\n" + |
7704 |
"3. ERROR in A.java (at line 12)\n" + |
7705 |
" Object foo(Object one, U two) { return null; }\n" + |
7706 |
" ^^^^^^^^^^^^^^^^^^^^^^\n" + |
7707 |
"Name clash: The method foo(Object, U) of type B<U> has the same erasure as foo(U, U) of type A<U> but does not override it\n" + |
7708 |
"----------\n" + |
7709 |
"4. ERROR in A.java (at line 12)\n" + |
7710 |
" Object foo(Object one, U two) { return null; }\n" + |
7711 |
" ^^^^^^^^^^^^^^^^^^^^^^\n" + |
7712 |
"The method foo(Object, U) of type B<U> must override a superclass method\n" + |
7713 |
"----------\n" + |
7714 |
"5. ERROR in A.java (at line 16)\n" + |
7715 |
" Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + |
7716 |
" ^^^^^^\n" + |
7717 |
"The return type is incompatible with A<U>.foo(U)\n" + |
7718 |
"----------\n" + |
7719 |
"6. ERROR in A.java (at line 18)\n" + |
7720 |
" Object foo(U one, U two) { return null; } // cannot override foo(U), incompatible return type error\n" + |
7721 |
" ^^^^^^\n" + |
7722 |
"The return type is incompatible with A<U>.foo(U, U)\n" + |
7723 |
"----------\n" |
7724 |
); |
7725 |
} |
7547 |
} |
7726 |
} |