Lines 5302-5319
Link Here
|
5302 |
// warning: create() in HashOrder overrides <U>create() in DoubleHash; return type requires unchecked conversion |
5302 |
// warning: create() in HashOrder overrides <U>create() in DoubleHash; return type requires unchecked conversion |
5303 |
); |
5303 |
); |
5304 |
} |
5304 |
} |
5305 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 |
5305 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 |
5306 |
public void test081() { |
5306 |
public void test081a() { |
5307 |
this.runNegativeTest( |
5307 |
this.runNegativeTest( |
5308 |
new String[] { |
5308 |
new String[] { |
5309 |
"X.java", |
5309 |
"X.java", |
5310 |
"public abstract class X<U> implements I {\n" + |
5310 |
"public abstract class X<U> implements I {\n" + |
5311 |
" public A<String> foo() { return null; }\n" + |
5311 |
" public A<String> foo() { return null; }\n" + |
5312 |
" public <S> A<U> bar() { return null; }\n" + |
|
|
5313 |
"}\n" + |
5312 |
"}\n" + |
5314 |
"interface I {\n" + |
5313 |
"interface I {\n" + |
5315 |
" <T> A<T> foo();\n" + |
5314 |
" <T> A<T> foo();\n" + |
5316 |
" <S> A<S> bar();\n" + |
|
|
5317 |
"}\n" + |
5315 |
"}\n" + |
5318 |
"class A<V> {}" |
5316 |
"class A<V> {}" |
5319 |
}, |
5317 |
}, |
Lines 5322-5335
Link Here
|
5322 |
" public A<String> foo() { return null; }\r\n" + |
5320 |
" public A<String> foo() { return null; }\r\n" + |
5323 |
" ^\n" + |
5321 |
" ^\n" + |
5324 |
"Type safety: The return type A<String> for foo() from the type X<U> needs unchecked conversion to conform to A<Object> from the type I\n" + |
5322 |
"Type safety: The return type A<String> for foo() from the type X<U> needs unchecked conversion to conform to A<Object> from the type I\n" + |
|
|
5323 |
"----------\n" |
5324 |
); |
5325 |
} |
5326 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 |
5327 |
public void test081b() { |
5328 |
this.runNegativeTest( |
5329 |
new String[] { |
5330 |
"X.java", |
5331 |
"public abstract class X<U> implements I {\n" + |
5332 |
" public <S> A<U> bar() { return null; }\n" + |
5333 |
"}\n" + |
5334 |
"interface I {\n" + |
5335 |
" <S> A<S> bar();\n" + |
5336 |
"}\n" + |
5337 |
"class A<V> {}" |
5338 |
}, |
5325 |
"----------\n" + |
5339 |
"----------\n" + |
5326 |
"2. ERROR in X.java (at line 3)\r\n" + |
5340 |
"1. ERROR in X.java (at line 2)\r\n" + |
5327 |
" public <S> A<U> bar() { return null; }\r\n" + |
5341 |
" public <S> A<U> bar() { return null; }\r\n" + |
5328 |
" ^^^^\n" + |
5342 |
" ^^^^\n" + |
5329 |
"The return type is incompatible with I.bar()\n" + |
5343 |
"The return type is incompatible with I.bar()\n" + |
5330 |
"----------\n" |
5344 |
"----------\n" |
5331 |
// <S>bar() in X cannot implement <S>bar() in I; attempting to use incompatible return type |
|
|
5332 |
// warning: foo() in X implements <T>foo() in I; return type requires unchecked conversion |
5333 |
); |
5345 |
); |
5334 |
} |
5346 |
} |
5335 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105339 |
5347 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105339 |
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" + |
7556 |
"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"); |
7557 |
"----------\n"); |
7546 |
} |
7558 |
} |
|
|
7559 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7560 |
public void test128() { |
7561 |
this.runNegativeTest( |
7562 |
new String[] { |
7563 |
"X.java", |
7564 |
"interface I<U, V> {\n" + |
7565 |
" U foo(Object o, V v);\n" + |
7566 |
"}\n" + |
7567 |
"public class X<U, V> implements I<U, V> {\n" + |
7568 |
" public Object foo(Object o, Object v) {\n" + |
7569 |
" return null;\n" + |
7570 |
" }\n" + |
7571 |
"}\n" |
7572 |
}, |
7573 |
"----------\n" + |
7574 |
"1. WARNING in X.java (at line 5)\n" + |
7575 |
" public Object foo(Object o, Object v) {\n" + |
7576 |
" ^^^^^^\n" + |
7577 |
"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" + |
7578 |
"----------\n"); |
7579 |
} |
7580 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7581 |
// variant - Object is not a subtype of Z |
7582 |
public void test129() { |
7583 |
this.runNegativeTest( |
7584 |
new String[] { |
7585 |
"X.java", |
7586 |
"interface I<U, V> {\n" + |
7587 |
" U foo(Object o, V v);\n" + |
7588 |
"}\n" + |
7589 |
"public class X<U extends Z, V> implements I<U, V> {\n" + |
7590 |
" public Object foo(Object o, Object v) {\n" + |
7591 |
" return null;\n" + |
7592 |
" }\n" + |
7593 |
"}\n" + |
7594 |
"class Z {\n" + |
7595 |
"}\n" |
7596 |
}, |
7597 |
"----------\n" + |
7598 |
"1. ERROR in X.java (at line 5)\n" + |
7599 |
" public Object foo(Object o, Object v) {\n" + |
7600 |
" ^^^^^^\n" + |
7601 |
"The return type is incompatible with I<U,V>.foo(Object, V)\n" + |
7602 |
"----------\n"); |
7603 |
} |
7604 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7605 |
// ** variant - Z<Object> is not a subtype of Z<U>, and |Z<U>| = Z, not Z<Object> |
7606 |
public void test130() { |
7607 |
this.runNegativeTest( |
7608 |
new String[] { |
7609 |
"X.java", |
7610 |
"interface I<U, V> {\n" + |
7611 |
" Z<U> foo(Object o, V v);\n" + |
7612 |
"}\n" + |
7613 |
"public class X<U, V> implements I<U, V> {\n" + |
7614 |
" public Z<Object> foo(Object o, Object v) {\n" + |
7615 |
" return null;\n" + |
7616 |
" }\n" + |
7617 |
"}\n" + |
7618 |
"class Z<T> {\n" + |
7619 |
"}" |
7620 |
}, |
7621 |
"----------\n" + |
7622 |
"1. ERROR in X.java (at line 5)\n" + |
7623 |
" public Z<Object> foo(Object o, Object v) {\n" + |
7624 |
" ^^^^^^^^^\n" + |
7625 |
"The return type is incompatible with I<U,V>.foo(Object, V)\n" + |
7626 |
"----------\n"); |
7627 |
} |
7628 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7629 |
// variant - two interfaces |
7630 |
public void test131() { |
7631 |
this.runNegativeTest( |
7632 |
new String[] { |
7633 |
"X.java", |
7634 |
"interface I<U, V> {\n" + |
7635 |
" U foo(Object o, V v);\n" + |
7636 |
"}\n" + |
7637 |
"interface X<U, V> extends I<U, V> {\n" + |
7638 |
" Object foo(Object o, Object v);\n" + |
7639 |
"}\n" |
7640 |
}, |
7641 |
"----------\n" + |
7642 |
"1. WARNING in X.java (at line 5)\n" + |
7643 |
" Object foo(Object o, Object v);\n" + |
7644 |
" ^^^^^^\n" + |
7645 |
"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" + |
7646 |
"----------\n"); |
7647 |
} |
7648 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7649 |
// variant - simpler test case |
7650 |
public void test132() { |
7651 |
this.runNegativeTest( |
7652 |
new String[] { |
7653 |
"X.java", |
7654 |
"interface I<U> {\n" + |
7655 |
" U foo();\n" + |
7656 |
"}\n" + |
7657 |
"public class X<U> implements I<U> {\n" + |
7658 |
" public Object foo() {\n" + |
7659 |
" return null;\n" + |
7660 |
" }\n" + |
7661 |
"}\n" |
7662 |
}, |
7663 |
"----------\n" + |
7664 |
"1. ERROR in X.java (at line 5)\n" + |
7665 |
" public Object foo() {\n" + |
7666 |
" ^^^^^^\n" + |
7667 |
"The return type is incompatible with I<U>.foo()\n" + |
7668 |
"----------\n"); |
7669 |
} |
7670 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7671 |
// variant |
7672 |
public void test133() { |
7673 |
this.runNegativeTest( |
7674 |
new String[] { |
7675 |
"X.java", |
7676 |
"public class X<U extends Z> {\n" + |
7677 |
" U foo() {\n" + |
7678 |
" return null;\n" + |
7679 |
" }\n" + |
7680 |
"}\n" + |
7681 |
"class Y<U extends Z> extends X<U> {\n" + |
7682 |
" public Z foo() {\n" + |
7683 |
" return null;\n" + |
7684 |
" }\n" + |
7685 |
"}\n" + |
7686 |
"class Z {\n" + |
7687 |
"}" |
7688 |
}, |
7689 |
"----------\n" + |
7690 |
"1. ERROR in X.java (at line 7)\n" + |
7691 |
" public Z foo() {\n" + |
7692 |
" ^\n" + |
7693 |
"The return type is incompatible with X<U>.foo()\n" + |
7694 |
"----------\n" + |
7695 |
"2. WARNING in X.java (at line 7)\n" + |
7696 |
" public Z foo() {\n" + |
7697 |
" ^^^^^\n" + |
7698 |
"The method foo() of type Y<U> should be tagged with @Override since it actually overrides a superclass method\n" + |
7699 |
"----------\n"); |
7700 |
} |
7701 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7702 |
// variant - unchecked conversion of ZC to ZC<String> that is a subtype of Z<String> |
7703 |
public void test134() { |
7704 |
this.runNegativeTest( |
7705 |
new String[] { |
7706 |
"X.java", |
7707 |
"public class X {\n" + |
7708 |
" Z<String> foo() {\n" + |
7709 |
" return null;\n" + |
7710 |
" }\n" + |
7711 |
"}\n" + |
7712 |
"class Y extends X {\n" + |
7713 |
" public ZC foo() {\n" + |
7714 |
" return null;\n" + |
7715 |
" }\n" + |
7716 |
"}\n" + |
7717 |
"class Z<T> {\n" + |
7718 |
"}\n" + |
7719 |
"class ZC<T> extends Z<T> {\n" + |
7720 |
"}" |
7721 |
}, |
7722 |
"----------\n" + |
7723 |
"1. WARNING in X.java (at line 7)\n" + |
7724 |
" public ZC foo() {\n" + |
7725 |
" ^^\n" + |
7726 |
"ZC is a raw type. References to generic type ZC<T> should be parameterized\n" + |
7727 |
"----------\n" + |
7728 |
"2. WARNING in X.java (at line 7)\n" + |
7729 |
" public ZC foo() {\n" + |
7730 |
" ^^\n" + |
7731 |
"Type safety: The return type ZC for foo() from the type Y needs unchecked conversion to conform to Z<String> from the type X\n" + |
7732 |
"----------\n" + |
7733 |
"3. WARNING in X.java (at line 7)\n" + |
7734 |
" public ZC foo() {\n" + |
7735 |
" ^^^^^\n" + |
7736 |
"The method foo() of type Y should be tagged with @Override since it actually overrides a superclass method\n" + |
7737 |
"----------\n"); |
7738 |
} |
7739 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7740 |
// variant - cast is not appropriate |
7741 |
public void test135() { |
7742 |
this.runNegativeTest( |
7743 |
new String[] { |
7744 |
"X.java", |
7745 |
"interface I<U, V> {\n" + |
7746 |
" U foo(Object o, V v);\n" + |
7747 |
"}\n" + |
7748 |
"interface J<U, V> extends I<U, V> {\n" + |
7749 |
" Object foo(Object o, V v);\n" + |
7750 |
"}\n" + |
7751 |
"class X {\n" + |
7752 |
" J<Integer, Integer> m1;\n" + |
7753 |
" I<Integer, Integer> m2 = (I<Integer, Integer>) m1;\n" + |
7754 |
"}" |
7755 |
}, |
7756 |
"----------\n" + |
7757 |
"1. ERROR in X.java (at line 5)\n" + |
7758 |
" Object foo(Object o, V v);\n" + |
7759 |
" ^^^^^^\n" + |
7760 |
"The return type is incompatible with I<U,V>.foo(Object, V)\n" + |
7761 |
"----------\n" + |
7762 |
"2. WARNING in X.java (at line 9)\n" + |
7763 |
" I<Integer, Integer> m2 = (I<Integer, Integer>) m1;\n" + |
7764 |
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
7765 |
"Unnecessary cast from J<Integer,Integer> to I<Integer,Integer>\n" + |
7766 |
"----------\n"); |
7767 |
} |
7768 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7769 |
// variant - type identity vs type equivalence |
7770 |
public void test136() { |
7771 |
this.runNegativeTest( |
7772 |
new String[] { |
7773 |
"X.java", |
7774 |
"interface I<U> {\n" + |
7775 |
" U foo(I<?> p);\n" + |
7776 |
"}\n" + |
7777 |
"public class X<U> implements I<U> {\n" + |
7778 |
" public Object foo(I<? extends Object> p) {\n" + |
7779 |
" return null;\n" + |
7780 |
" }\n" + |
7781 |
"}\n" |
7782 |
}, |
7783 |
"----------\n" + |
7784 |
"1. ERROR in X.java (at line 5)\n" + |
7785 |
" public Object foo(I<? extends Object> p) {\n" + |
7786 |
" ^^^^^^\n" + |
7787 |
"The return type is incompatible with I<U>.foo(I<?>)\n" + |
7788 |
"----------\n"); |
7789 |
} |
7790 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7791 |
// variant - type identity vs type equivalence |
7792 |
public void test137() { |
7793 |
this.runNegativeTest( |
7794 |
new String[] { |
7795 |
"X.java", |
7796 |
"interface I<U> {\n" + |
7797 |
" U foo(I<? extends Object> p);\n" + |
7798 |
"}\n" + |
7799 |
"public class X<U> implements I<U> {\n" + |
7800 |
" public Object foo(I<?> p) {\n" + |
7801 |
" return null;\n" + |
7802 |
" }\n" + |
7803 |
"}\n" |
7804 |
}, |
7805 |
"----------\n" + |
7806 |
"1. ERROR in X.java (at line 5)\n" + |
7807 |
" public Object foo(I<?> p) {\n" + |
7808 |
" ^^^^^^\n" + |
7809 |
"The return type is incompatible with I<U>.foo(I<? extends Object>)\n" + |
7810 |
"----------\n"); |
7811 |
} |
7812 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7813 |
// variant - @Override annotation |
7814 |
public void test138() { |
7815 |
this.runNegativeTest( |
7816 |
new String[] { |
7817 |
"X.java", |
7818 |
"public class X<U> {\n" + |
7819 |
" U foo() { return null; }\n" + |
7820 |
"}\n" + |
7821 |
"class Y<U> extends X<U> {\n" + |
7822 |
" @Override // does not override error\n" + |
7823 |
" Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + |
7824 |
"}" |
7825 |
}, |
7826 |
"----------\n" + |
7827 |
"1. ERROR in X.java (at line 6)\n" + |
7828 |
" Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + |
7829 |
" ^^^^^^\n" + |
7830 |
"The return type is incompatible with X<U>.foo()\n" + |
7831 |
"----------\n"); |
7832 |
}// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7833 |
// variant - @Override annotation |
7834 |
public void test139() { |
7835 |
this.runNegativeTest( |
7836 |
new String[] { |
7837 |
"X.java", |
7838 |
"public class X<U> {\n" + |
7839 |
" U foo(U one) { return null; }\n" + |
7840 |
"}\n" + |
7841 |
"class Y<U> extends X<U> {\n" + |
7842 |
" @Override\n" + |
7843 |
" Object foo(Object one) { return null; } // unchecked conversion warning\n" + |
7844 |
"}" |
7845 |
}, |
7846 |
"----------\n" + |
7847 |
"1. WARNING in X.java (at line 6)\n" + |
7848 |
" Object foo(Object one) { return null; } // unchecked conversion warning\n" + |
7849 |
" ^^^^^^\n" + |
7850 |
"Type safety: The return type Object for foo(Object) from the type Y<U> needs unchecked conversion to conform to U from the type X<U>\n" + |
7851 |
"----------\n"); |
7852 |
} |
7853 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7854 |
// variant - @Override annotation |
7855 |
public void test140() { |
7856 |
this.runNegativeTest( |
7857 |
new String[] { |
7858 |
"X.java", |
7859 |
"public class X<U> {\n" + |
7860 |
" U foo(U one, U two) { return null; }\n" + |
7861 |
"}\n" + |
7862 |
"class Y<U> extends X<U> {\n" + |
7863 |
" @Override // does not override error\n" + |
7864 |
" Object foo(Object one, U two) { return null; }\n" + |
7865 |
"}" |
7866 |
}, |
7867 |
"----------\n" + |
7868 |
"1. ERROR in X.java (at line 6)\n" + |
7869 |
" Object foo(Object one, U two) { return null; }\n" + |
7870 |
" ^^^^^^^^^^^^^^^^^^^^^^\n" + |
7871 |
"Name clash: The method foo(Object, U) of type Y<U> has the same erasure as foo(U, U) of type X<U> but does not override it\n" + |
7872 |
"----------\n" + |
7873 |
"2. ERROR in X.java (at line 6)\n" + |
7874 |
" Object foo(Object one, U two) { return null; }\n" + |
7875 |
" ^^^^^^^^^^^^^^^^^^^^^^\n" + |
7876 |
(complianceLevel.compareTo(COMPLIANCE_1_5) <= 0 ? |
7877 |
"The method foo(Object, U) of type Y<U> must override a superclass method\n" : |
7878 |
"The method foo(Object, U) of type Y<U> must override or implement a supertype method\n") + |
7879 |
"----------\n"); |
7880 |
} |
7881 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7882 |
// variant - @Override annotation |
7883 |
public void test141() { |
7884 |
this.runNegativeTest( |
7885 |
new String[] { |
7886 |
"X.java", |
7887 |
"public class X<U> {\n" + |
7888 |
" U foo(U one) { return null; }\n" + |
7889 |
"}\n" + |
7890 |
"class Y<U> extends X<U> {\n" + |
7891 |
" @Override // does not override error\n" + |
7892 |
" Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + |
7893 |
"}" |
7894 |
}, |
7895 |
"----------\n" + |
7896 |
"1. ERROR in X.java (at line 6)\n" + |
7897 |
" Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + |
7898 |
" ^^^^^^\n" + |
7899 |
"The return type is incompatible with X<U>.foo(U)\n" + |
7900 |
"----------\n"); |
7901 |
} |
7902 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
7903 |
// variant - @Override annotation |
7904 |
public void test142() { |
7905 |
this.runNegativeTest( |
7906 |
new String[] { |
7907 |
"X.java", |
7908 |
"public class X<U> {\n" + |
7909 |
" U foo(U one, U two) { return null; }\n" + |
7910 |
"}\n" + |
7911 |
"class Y<U> extends X<U> {\n" + |
7912 |
" @Override // does not override error\n" + |
7913 |
" Object foo(U one, U two) { return null; } // cannot override foo(U,U), incompatible return type error\n" + |
7914 |
"}" |
7915 |
}, |
7916 |
"----------\n" + |
7917 |
"1. ERROR in X.java (at line 6)\n" + |
7918 |
" Object foo(U one, U two) { return null; } // cannot override foo(U,U), incompatible return type error\n" + |
7919 |
" ^^^^^^\n" + |
7920 |
"The return type is incompatible with X<U>.foo(U, U)\n" + |
7921 |
"----------\n"); |
7922 |
} |
7547 |
} |
7923 |
} |