Commit 58d73da3 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch '317837-fix-cast-regression' into 'master'

Resolve "Apparent regression in GeneratorAdapter.java `cast` function"

Closes #317837

See merge request !189
parents d0afe0cd bb3bdde4
Pipeline #2275 passed with stage
in 7 minutes and 33 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("Cannot cast from " + from + " to " + to);
}
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();
}
}
}
......
......@@ -407,6 +407,11 @@ public class GeneratorAdapterTest {
assertEquals("I2C", new Generator().cast(Type.INT_TYPE, Type.CHAR_TYPE));
assertEquals("I2S", new Generator().cast(Type.INT_TYPE, Type.SHORT_TYPE));
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