Commit 7d045e01 authored by Eric Bruneton's avatar Eric Bruneton

Fix the regression, make previously added tests pass.

parent 434c3c63
Pipeline #2235 passed with stage
in 7 minutes and 13 seconds
......@@ -741,6 +741,12 @@ public class GeneratorAdapter extends LocalVariablesSorter {
*/
public void cast(final Type from, final Type to) {
if (from != to) {
if (from.getSort() < Type.BOOLEAN
|| from.getSort() > Type.DOUBLE
|| to.getSort() < Type.BOOLEAN
|| to.getSort() > Type.DOUBLE) {
throw new IllegalArgumentException();
}
if (from == Type.DOUBLE_TYPE) {
if (to == Type.FLOAT_TYPE) {
mv.visitInsn(Opcodes.D2F);
......@@ -781,8 +787,6 @@ public class GeneratorAdapter extends LocalVariablesSorter {
mv.visitInsn(Opcodes.I2L);
} else if (to == Type.SHORT_TYPE) {
mv.visitInsn(Opcodes.I2S);
} else {
throw new IllegalArgumentException();
}
}
}
......
......@@ -410,6 +410,8 @@ public class GeneratorAdapterTest {
assertEquals("", new Generator().cast(Type.BYTE_TYPE, Type.INT_TYPE));
assertEquals("", new Generator().cast(Type.SHORT_TYPE, Type.INT_TYPE));
assertThrows(
IllegalArgumentException.class, () -> new Generator().cast(Type.VOID_TYPE, Type.INT_TYPE));
assertThrows(
IllegalArgumentException.class, () -> new Generator().cast(Type.INT_TYPE, Type.VOID_TYPE));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment