提交 1709cde7 编写于 作者: M mcimadamore

6714835: Safe cast is rejected (with warning) by javac

Summary: Rules for unchecked cast conversion do not take into account type-containment
Reviewed-by: jjg
上级 2369f6f7
......@@ -3151,7 +3151,7 @@ public class Types {
return to.isParameterized() &&
(!(isUnbounded(to) ||
isSubtype(from, to) ||
((subFrom != null) && isSameType(subFrom, to))));
((subFrom != null) && containsType(to.allparams(), subFrom.allparams()))));
}
private List<Type> superClosure(Type t, Type s) {
......
T6467183a.java:16:26: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), T6467183a<T>.B, T6467183a<T>.A<T>
T6467183a.java:24:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), T6467183a<T>.A<java.lang.Integer>, T6467183a<T>.C<? extends java.lang.Number>
T6467183a.java:28:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), T6467183a<T>.A<java.lang.Integer>, T6467183a<T>.C<? extends java.lang.Integer>
- compiler.err.warnings.and.werror
1 error
3 warnings
1 warning
/*
* @test /nodynamiccopyright/
* @author mcimadamore
* @bug 6714835
* @summary Safe cast is rejected (with warning) by javac
* @compile/fail/ref=T6714835.out -Xlint:unchecked -Werror -XDrawDiagnostics T6714835.java
*/
import java.util.*;
class T6714835 {
void cast1(Iterable<? extends Integer> x) {
Collection<? extends Number> x1 = (Collection<? extends Number>)x; //ok
Collection<? super Integer> x2 = (Collection<? super Integer>)x; //warn
}
void cast2(Iterable<? super Number> x) {
Collection<? super Integer> x1 = (Collection<? super Integer>)x; //ok
Collection<? extends Number> x2 = (Collection<? extends Number>)x; //warn
}
}
T6714835.java:14:71: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Iterable<compiler.misc.type.captureof: 1, ? extends java.lang.Integer>, java.util.Collection<? super java.lang.Integer>
T6714835.java:19:73: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Iterable<compiler.misc.type.captureof: 1, ? super java.lang.Number>, java.util.Collection<? extends java.lang.Number>
- compiler.err.warnings.and.werror
1 error
2 warnings
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册