cast from Short to char is prohibited

This commit is contained in:
Alexey Kudravtsev
2014-07-18 14:58:43 +04:00
parent 685fdb418a
commit 1c5a03589e
2 changed files with 95 additions and 0 deletions
@@ -94,4 +94,96 @@ class C {
void asLongs(Integer i) {
long l = (long) i;
}
void foo(Object o) {}
public void cast2(Byte operand) {
foo((<warning descr="Casting 'operand' to 'byte' is redundant">byte</warning>)operand);
foo((short)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Byte' to 'char'">(char)operand</error>);
foo((int)operand);
foo((long)operand);
foo((float)operand);
foo((double)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Byte' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Short operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Short' to 'byte'">(byte)operand</error>);
foo((<warning descr="Casting 'operand' to 'short' is redundant">short</warning>)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Short' to 'char'">(char)operand</error>);
foo((int)operand);
foo((long)operand);
foo((float)operand);
foo((double)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Short' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Character operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'byte'">(byte)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'short'">(short)operand</error>);
foo((<warning descr="Casting 'operand' to 'char' is redundant">char</warning>)operand);
foo((int)operand);
foo((long)operand);
foo((float)operand);
foo((double)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Character' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Integer operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'byte'">(byte)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'short'">(short)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'char'">(char)operand</error>);
foo((<warning descr="Casting 'operand' to 'int' is redundant">int</warning>)operand);
foo((long)operand);
foo((float)operand);
foo((double)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Integer' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Long operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'byte'">(byte)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'short'">(short)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'char'">(char)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'int'">(int)operand</error>);
foo((<warning descr="Casting 'operand' to 'long' is redundant">long</warning>)operand);
foo((float)operand);
foo((double)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Float operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'byte'">(byte)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'short'">(short)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'char'">(char)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'int'">(int)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'long'">(long)operand</error>);
foo((<warning descr="Casting 'operand' to 'float' is redundant">float</warning>)operand);
foo((double)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Float' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Double operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'byte'">(byte)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'short'">(short)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'char'">(char)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'int'">(int)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'long'">(long)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'float'">(float)operand</error>);
foo((<warning descr="Casting 'operand' to 'double' is redundant">double</warning>)operand);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Double' to 'boolean'">(boolean)operand</error>);
}
public void cast2(Boolean operand) {
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'byte'">(byte)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'short'">(short)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'char'">(char)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'int'">(int)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'long'">(long)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'float'">(float)operand</error>);
foo(<error descr="Inconvertible types; cannot cast 'java.lang.Boolean' to 'double'">(double)operand</error>);
foo((<warning descr="Casting 'operand' to 'boolean' is redundant">boolean</warning>)operand);
}
public void cast2(Object operand) {
foo((<warning descr="Casting 'operand' to 'byte' is redundant">byte</warning>)operand);
foo((<warning descr="Casting 'operand' to 'short' is redundant">short</warning>)operand);
foo((<warning descr="Casting 'operand' to 'char' is redundant">char</warning>)operand);
foo((<warning descr="Casting 'operand' to 'int' is redundant">int</warning>)operand);
foo((<warning descr="Casting 'operand' to 'long' is redundant">long</warning>)operand);
foo((<warning descr="Casting 'operand' to 'float' is redundant">float</warning>)operand);
foo((<warning descr="Casting 'operand' to 'double' is redundant">double</warning>)operand);
foo((<warning descr="Casting 'operand' to 'boolean' is redundant">boolean</warning>)operand);
}
}