Index: GenericTypeTest.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java,v retrieving revision 1.319 diff -u -r1.319 GenericTypeTest.java --- GenericTypeTest.java 17 Jun 2005 09:26:42 -0000 1.319 +++ GenericTypeTest.java 21 Jun 2005 08:32:48 -0000 @@ -21388,7 +21388,7 @@ "----------\n"); } //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98538 -public void _test742() { +public void test742() { this.runNegativeTest( new String[] { "X.java", @@ -21396,79 +21396,53 @@ "\n" + " public class X {\n" + " \n" + - " /**Subclasses are parameterized by their own type*/\n" + - " private static abstract class SelfType>{\n" + - " public abstract T getThis();\n" + + " static abstract class SelfType>{\n" + " }\n" + " \n" + - " /**Supertype inherits directly from the parameterized SelfType*/\n" + - " private static class SuperType extends SelfType{\n" + - " @Override\n" + - " public SuperType getThis(){\n" + - " return this;\n" + - " }\n" + + " static class SuperType extends SelfType{\n" + " }\n" + " \n" + - " /**Subtype inherits indirectly from the parameterized SelfType*/\n" + - " private static class SubType extends SuperType{}\n" + + " static class SubType extends SuperType{}\n" + " \n" + - " /**Creates a list containing a single SelfType*/\n" + - " public static > List makeSingletonList(T t){\n" + + " static > List makeSingletonList(T t){\n" + " return Collections.singletonList(t);\n" + " }\n" + " \n" + - " /**\n" + - " * Creates a list containing a single SelfType, allowing the list\'s\n" + - " * element-type to be a supertype of the type of its single element\n" + - " */\n" + - " public static ,S extends T> List makeSingletonList2(S s){\n" + - " return Collections.singletonList((T)s);\n" + + " static ,S extends T> List makeSingletonList2(S s){\n" + + " return Collections.singletonList((T)s); // #0\n" + " }\n" + " \n" + " public static void main(String[] args){\n" + - " /*making lists of super types works fine ...*/\n" + - " makeSingletonList(new SuperType());\n" + - " List lsup = makeSingletonList(new SuperType());\n" + - " \n" + - " /*but we can\'t make a list of sub types; seems weird ...*/\n" + - " List lsub = makeSingletonList(new SubType()); //ERROR\n" + - " \n" + - " /*can\'t even call it w/o assigning the return value:*/\n" + - " makeSingletonList(new SubType()); //ERROR\n" + - " \n" + - " \n" + - " /*so instead, we should be able to make lists of super type containing sub type elements*/\n" + - " makeSingletonList2(new SubType()); //ERROR\n" + - " /*even if we assign the return value:*/\n" + - " lsup = makeSingletonList2(new SubType()); // ERROR (eclipse is okay with this though)\n" + - " /*this still doesn\'t work either:*/\n" + - " lsub = makeSingletonList2(new SubType()); // ERROR\n" + - " \n" + - " /*we can make lists of super type this way though*/\n" + - " makeSingletonList2(new SuperType()); // (eclipse doesn\'t like this though)\n" + - " /*also ok if we assign the return value*/\n" + - " lsup = makeSingletonList2(new SuperType());\n" + + " makeSingletonList(new SuperType()); // #1 - OK\n" + + " List lsup = makeSingletonList(new SuperType()); // #2 - OK\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + + " makeSingletonList(new SubType()); // #4 - ERROR\n" + + " makeSingletonList2(new SubType()); // #5 - ERROR\n" + + " lsup = makeSingletonList2(new SubType()); // #6 - OK\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + + " makeSingletonList2(new SuperType()); // #8 - OK\n" + + " lsup = makeSingletonList2(new SuperType()); // #9 - OK\n" + " }\n" + "}\n" }, "----------\n" + - "1. ERROR in X.java (at line 40)\n" + - " List lsub = makeSingletonList(new SubType()); //ERROR\n" + + "1. ERROR in X.java (at line 24)\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + " ^^^^^^^^^^^^^^^^^\n" + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType) since the type X.SubType is not a valid substitute for the bounded parameter >\n" + "----------\n" + - "2. ERROR in X.java (at line 43)\n" + - " makeSingletonList(new SubType()); //ERROR\n" + + "2. ERROR in X.java (at line 25)\n" + + " makeSingletonList(new SubType()); // #4 - ERROR\n" + " ^^^^^^^^^^^^^^^^^\n" + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType) since the type X.SubType is not a valid substitute for the bounded parameter >\n" + "----------\n" + - "3. ERROR in X.java (at line 47)\n" + - " makeSingletonList2(new SubType()); //ERROR\n" + + "3. ERROR in X.java (at line 26)\n" + + " makeSingletonList2(new SubType()); // #5 - ERROR\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType) since the type X.SubType is not a valid substitute for the bounded parameter >\n" + "----------\n" + - "4. ERROR in X.java (at line 51)\n" + - " lsub = makeSingletonList2(new SubType()); // ERROR\n" + + "4. ERROR in X.java (at line 28)\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + " ^^^^^^^^^^^^^^^^^^\n" + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType) since the type X.SubType is not a valid substitute for the bounded parameter >\n" + "----------\n"); @@ -22010,5 +21984,99 @@ }, ""); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100527 +public void test764() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + " \n" + + "interface IIfClosure {}\n" + + " \n" + + "public class X {\n" + + " public X(String label, HashMap bindings) {\n" + + " this(label, bindings, (List)Collections.emptyList());\n" + + " }\n" + + " \n" + + " public X(String label, HashMap bindings, Collection coll) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\r\n" + + " this(label, bindings, (List)Collections.emptyList());\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 +public void test765() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static T f1() throws Exception{\n" + + " return null;\n" + + " }\n" + + " static U f2() throws Exception {\n" + + " return f1();\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 +public void test766() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Cloneable> {\n" + + " public T clone();\n" + + "}\n" + + "\n" + + "interface CloneableMap> extends Map, Cloneable> {\n" + + "}\n" + + "\n" + + "interface C> extends Cloneable {\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " CloneableMap> map = null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " CloneableMap> map = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter > of the type CloneableMap\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 - variation +public void test767() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Cloneable> {\n" + + " public T clone();\n" + + "}\n" + + "\n" + + "interface CloneableMap> extends Map, Cloneable> {\n" + + "}\n" + + "\n" + + "interface C extends Cloneable {\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " CloneableMap map = null;\n" + + " }\n" + + "}\n", + }, + ""); +} }