Lines 21388-21394
Link Here
|
21388 |
"----------\n"); |
21388 |
"----------\n"); |
21389 |
} |
21389 |
} |
21390 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98538 |
21390 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98538 |
21391 |
public void _test742() { |
21391 |
public void test742() { |
21392 |
this.runNegativeTest( |
21392 |
this.runNegativeTest( |
21393 |
new String[] { |
21393 |
new String[] { |
21394 |
"X.java", |
21394 |
"X.java", |
Lines 21396-21474
Link Here
|
21396 |
"\n" + |
21396 |
"\n" + |
21397 |
" public class X {\n" + |
21397 |
" public class X {\n" + |
21398 |
" \n" + |
21398 |
" \n" + |
21399 |
" /**Subclasses are parameterized by their own type*/\n" + |
21399 |
" static abstract class SelfType<T extends SelfType<T>>{\n" + |
21400 |
" private static abstract class SelfType<T extends SelfType<T>>{\n" + |
|
|
21401 |
" public abstract T getThis();\n" + |
21402 |
" }\n" + |
21400 |
" }\n" + |
21403 |
" \n" + |
21401 |
" \n" + |
21404 |
" /**Supertype inherits directly from the parameterized SelfType*/\n" + |
21402 |
" static class SuperType extends SelfType<SuperType>{\n" + |
21405 |
" private static class SuperType extends SelfType<SuperType>{\n" + |
|
|
21406 |
" @Override\n" + |
21407 |
" public SuperType getThis(){\n" + |
21408 |
" return this;\n" + |
21409 |
" }\n" + |
21410 |
" }\n" + |
21403 |
" }\n" + |
21411 |
" \n" + |
21404 |
" \n" + |
21412 |
" /**Subtype inherits indirectly from the parameterized SelfType*/\n" + |
21405 |
" static class SubType extends SuperType{}\n" + |
21413 |
" private static class SubType extends SuperType{}\n" + |
|
|
21414 |
" \n" + |
21406 |
" \n" + |
21415 |
" /**Creates a list containing a single SelfType*/\n" + |
21407 |
" static <T extends SelfType<T>> List<T> makeSingletonList(T t){\n" + |
21416 |
" public static <T extends SelfType<T>> List<T> makeSingletonList(T t){\n" + |
|
|
21417 |
" return Collections.singletonList(t);\n" + |
21408 |
" return Collections.singletonList(t);\n" + |
21418 |
" }\n" + |
21409 |
" }\n" + |
21419 |
" \n" + |
21410 |
" \n" + |
21420 |
" /**\n" + |
21411 |
" static <T extends SelfType<T>,S extends T> List<T> makeSingletonList2(S s){\n" + |
21421 |
" * Creates a list containing a single SelfType, allowing the list\'s\n" + |
21412 |
" return Collections.singletonList((T)s); // #0\n" + |
21422 |
" * element-type to be a supertype of the type of its single element\n" + |
|
|
21423 |
" */\n" + |
21424 |
" public static <T extends SelfType<T>,S extends T> List<T> makeSingletonList2(S s){\n" + |
21425 |
" return Collections.singletonList((T)s);\n" + |
21426 |
" }\n" + |
21413 |
" }\n" + |
21427 |
" \n" + |
21414 |
" \n" + |
21428 |
" public static void main(String[] args){\n" + |
21415 |
" public static void main(String[] args){\n" + |
21429 |
" /*making lists of super types works fine ...*/\n" + |
21416 |
" makeSingletonList(new SuperType()); // #1 - OK\n" + |
21430 |
" makeSingletonList(new SuperType());\n" + |
21417 |
" List<SuperType> lsup = makeSingletonList(new SuperType()); // #2 - OK\n" + |
21431 |
" List<SuperType> lsup = makeSingletonList(new SuperType());\n" + |
21418 |
" List<SubType> lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + |
21432 |
" \n" + |
21419 |
" makeSingletonList(new SubType()); // #4 - ERROR\n" + |
21433 |
" /*but we can\'t make a list of sub types; seems weird ...*/\n" + |
21420 |
" makeSingletonList2(new SubType()); // #5 - ERROR\n" + |
21434 |
" List<SubType> lsub = makeSingletonList(new SubType()); //ERROR\n" + |
21421 |
" lsup = makeSingletonList2(new SubType()); // #6 - OK\n" + |
21435 |
" \n" + |
21422 |
" lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + |
21436 |
" /*can\'t even call it w/o assigning the return value:*/\n" + |
21423 |
" makeSingletonList2(new SuperType()); // #8 - OK\n" + |
21437 |
" makeSingletonList(new SubType()); //ERROR\n" + |
21424 |
" lsup = makeSingletonList2(new SuperType()); // #9 - OK\n" + |
21438 |
" \n" + |
|
|
21439 |
" \n" + |
21440 |
" /*so instead, we should be able to make lists of super type containing sub type elements*/\n" + |
21441 |
" makeSingletonList2(new SubType()); //ERROR\n" + |
21442 |
" /*even if we assign the return value:*/\n" + |
21443 |
" lsup = makeSingletonList2(new SubType()); // ERROR (eclipse is okay with this though)\n" + |
21444 |
" /*this still doesn\'t work either:*/\n" + |
21445 |
" lsub = makeSingletonList2(new SubType()); // ERROR\n" + |
21446 |
" \n" + |
21447 |
" /*we can make lists of super type this way though*/\n" + |
21448 |
" makeSingletonList2(new SuperType()); // (eclipse doesn\'t like this though)\n" + |
21449 |
" /*also ok if we assign the return value*/\n" + |
21450 |
" lsup = makeSingletonList2(new SuperType());\n" + |
21451 |
" }\n" + |
21425 |
" }\n" + |
21452 |
"}\n" |
21426 |
"}\n" |
21453 |
}, |
21427 |
}, |
21454 |
"----------\n" + |
21428 |
"----------\n" + |
21455 |
"1. ERROR in X.java (at line 40)\n" + |
21429 |
"1. ERROR in X.java (at line 24)\n" + |
21456 |
" List<SubType> lsub = makeSingletonList(new SubType()); //ERROR\n" + |
21430 |
" List<SubType> lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + |
21457 |
" ^^^^^^^^^^^^^^^^^\n" + |
21431 |
" ^^^^^^^^^^^^^^^^^\n" + |
21458 |
"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 <T extends X.SelfType<T>>\n" + |
21432 |
"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 <T extends X.SelfType<T>>\n" + |
21459 |
"----------\n" + |
21433 |
"----------\n" + |
21460 |
"2. ERROR in X.java (at line 43)\n" + |
21434 |
"2. ERROR in X.java (at line 25)\n" + |
21461 |
" makeSingletonList(new SubType()); //ERROR\n" + |
21435 |
" makeSingletonList(new SubType()); // #4 - ERROR\n" + |
21462 |
" ^^^^^^^^^^^^^^^^^\n" + |
21436 |
" ^^^^^^^^^^^^^^^^^\n" + |
21463 |
"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 <T extends X.SelfType<T>>\n" + |
21437 |
"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 <T extends X.SelfType<T>>\n" + |
21464 |
"----------\n" + |
21438 |
"----------\n" + |
21465 |
"3. ERROR in X.java (at line 47)\n" + |
21439 |
"3. ERROR in X.java (at line 26)\n" + |
21466 |
" makeSingletonList2(new SubType()); //ERROR\n" + |
21440 |
" makeSingletonList2(new SubType()); // #5 - ERROR\n" + |
21467 |
" ^^^^^^^^^^^^^^^^^^\n" + |
21441 |
" ^^^^^^^^^^^^^^^^^^\n" + |
21468 |
"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 <T extends X.SelfType<T>>\n" + |
21442 |
"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 <T extends X.SelfType<T>>\n" + |
21469 |
"----------\n" + |
21443 |
"----------\n" + |
21470 |
"4. ERROR in X.java (at line 51)\n" + |
21444 |
"4. ERROR in X.java (at line 28)\n" + |
21471 |
" lsub = makeSingletonList2(new SubType()); // ERROR\n" + |
21445 |
" lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + |
21472 |
" ^^^^^^^^^^^^^^^^^^\n" + |
21446 |
" ^^^^^^^^^^^^^^^^^^\n" + |
21473 |
"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 <T extends X.SelfType<T>>\n" + |
21447 |
"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 <T extends X.SelfType<T>>\n" + |
21474 |
"----------\n"); |
21448 |
"----------\n"); |
Lines 22010-22014
Link Here
|
22010 |
}, |
21984 |
}, |
22011 |
""); |
21985 |
""); |
22012 |
} |
21986 |
} |
|
|
21987 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100527 |
21988 |
public void test764() { |
21989 |
this.runNegativeTest( |
21990 |
new String[] { |
21991 |
"X.java", |
21992 |
"import java.util.*;\n" + |
21993 |
" \n" + |
21994 |
"interface IIfClosure {}\n" + |
21995 |
" \n" + |
21996 |
"public class X {\n" + |
21997 |
" public X(String label, HashMap<String,Object> bindings) {\n" + |
21998 |
" this(label, bindings, (List<IIfClosure>)Collections.emptyList());\n" + |
21999 |
" }\n" + |
22000 |
" \n" + |
22001 |
" public X(String label, HashMap<String,Object> bindings, Collection<IIfClosure> coll) {\n" + |
22002 |
" }\n" + |
22003 |
"}\n", |
22004 |
}, |
22005 |
"----------\n" + |
22006 |
"1. ERROR in X.java (at line 7)\r\n" + |
22007 |
" this(label, bindings, (List<IIfClosure>)Collections.emptyList());\r\n" + |
22008 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
22009 |
"Cannot cast from List<Object> to List<IIfClosure>\n" + |
22010 |
"----------\n"); |
22011 |
} |
22012 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 |
22013 |
public void test765() { |
22014 |
this.runConformTest( |
22015 |
new String[] { |
22016 |
"X.java", |
22017 |
"public class X {\n" + |
22018 |
" static <T extends X> T f1() throws Exception{\n" + |
22019 |
" return null;\n" + |
22020 |
" }\n" + |
22021 |
" static <U extends X> U f2() throws Exception {\n" + |
22022 |
" return f1();\n" + |
22023 |
" }\n" + |
22024 |
"}\n", |
22025 |
}, |
22026 |
""); |
22027 |
} |
22028 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 |
22029 |
public void test766() { |
22030 |
this.runNegativeTest( |
22031 |
new String[] { |
22032 |
"X.java", |
22033 |
"import java.util.*;\n" + |
22034 |
"\n" + |
22035 |
"interface Cloneable<T extends Cloneable<T>> {\n" + |
22036 |
" public T clone();\n" + |
22037 |
"}\n" + |
22038 |
"\n" + |
22039 |
"interface CloneableMap<K, V extends Cloneable<V>> extends Map<K, V>, Cloneable<CloneableMap<K, V>> {\n" + |
22040 |
"}\n" + |
22041 |
"\n" + |
22042 |
"interface C<T extends C<T>> extends Cloneable<T> {\n" + |
22043 |
"}\n" + |
22044 |
"public class X {\n" + |
22045 |
" void foo() {\n" + |
22046 |
" CloneableMap<String, C<?>> map = null;\n" + |
22047 |
" }\n" + |
22048 |
"}\n", |
22049 |
}, |
22050 |
"----------\n" + |
22051 |
"1. ERROR in X.java (at line 14)\n" + |
22052 |
" CloneableMap<String, C<?>> map = null;\n" + |
22053 |
" ^\n" + |
22054 |
"Bound mismatch: The type C<?> is not a valid substitute for the bounded parameter <V extends Cloneable<V>> of the type CloneableMap<K,V>\n" + |
22055 |
"----------\n"); |
22056 |
} |
22057 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 - variation |
22058 |
public void test767() { |
22059 |
this.runConformTest( |
22060 |
new String[] { |
22061 |
"X.java", |
22062 |
"import java.util.*;\n" + |
22063 |
"\n" + |
22064 |
"interface Cloneable<T extends Cloneable<T>> {\n" + |
22065 |
" public T clone();\n" + |
22066 |
"}\n" + |
22067 |
"\n" + |
22068 |
"interface CloneableMap<K, V extends Cloneable<V>> extends Map<K, V>, Cloneable<CloneableMap<K, V>> {\n" + |
22069 |
"}\n" + |
22070 |
"\n" + |
22071 |
"interface C extends Cloneable<C> {\n" + |
22072 |
"}\n" + |
22073 |
"public class X {\n" + |
22074 |
" void foo() {\n" + |
22075 |
" CloneableMap<String, C> map = null;\n" + |
22076 |
" }\n" + |
22077 |
"}\n", |
22078 |
}, |
22079 |
""); |
22080 |
} |
22013 |
} |
22081 |
} |
22014 |
|
22082 |
|