mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-14 09:53:18 +00:00
6714835: Safe cast is rejected (with warning) by javac
Rules for unchecked cast conversion do not take into account type-containment Reviewed-by: jjg
This commit is contained in:
parent
d4d5f60edc
commit
e202a05c38
@ -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) {
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
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
|
||||
|
||||
21
langtools/test/tools/javac/cast/6714835/T6714835.java
Normal file
21
langtools/test/tools/javac/cast/6714835/T6714835.java
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* @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
|
||||
}
|
||||
}
|
||||
5
langtools/test/tools/javac/cast/6714835/T6714835.out
Normal file
5
langtools/test/tools/javac/cast/6714835/T6714835.out
Normal file
@ -0,0 +1,5 @@
|
||||
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
|
||||
Loading…
x
Reference in New Issue
Block a user