From dbaaa8091896901ed61cacd3ee9d507a201fc01b Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Mon, 16 Dec 2013 20:04:16 +0400 Subject: [PATCH] Add i2b cast boxing Int to Byte? or Short? (fix android tests) --- .../backend/src/org/jetbrains/jet/codegen/StackValue.java | 7 +++---- .../codegen/bytecodeText/constants/nullableByteAndShort.kt | 5 +++++ .../jetbrains/jet/codegen/BytecodeTextTestGenerated.java | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 1b5cf7816cb..3564a26d024 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -160,12 +160,14 @@ public abstract class StackValue { private static void box(Type type, Type toType, InstructionAdapter v) { if (type == Type.BYTE_TYPE || toType.getInternalName().equals(NULLABLE_BYTE_TYPE_NAME) && type == Type.INT_TYPE) { + v.cast(type, Type.BYTE_TYPE); v.invokestatic(NULLABLE_BYTE_TYPE_NAME, "valueOf", "(B)L" + NULLABLE_BYTE_TYPE_NAME + ";"); } else if (type == Type.SHORT_TYPE || toType.getInternalName().equals(NULLABLE_SHORT_TYPE_NAME) && type == Type.INT_TYPE) { + v.cast(type, Type.SHORT_TYPE); v.invokestatic(NULLABLE_SHORT_TYPE_NAME, "valueOf", "(S)L" + NULLABLE_SHORT_TYPE_NAME + ";"); } - else if (toType.getInternalName().equals(NULLABLE_LONG_TYPE_NAME) && type == Type.INT_TYPE) { + else if (type == Type.LONG_TYPE || toType.getInternalName().equals(NULLABLE_LONG_TYPE_NAME) && type == Type.INT_TYPE) { v.cast(type, Type.LONG_TYPE); v.invokestatic(NULLABLE_LONG_TYPE_NAME, "valueOf", "(J)L" + NULLABLE_LONG_TYPE_NAME +";"); } @@ -178,9 +180,6 @@ public abstract class StackValue { else if (type == Type.CHAR_TYPE) { v.invokestatic("java/lang/Character", "valueOf", "(C)Ljava/lang/Character;"); } - else if (type == Type.LONG_TYPE) { - v.invokestatic("java/lang/Long", "valueOf", "(J)Ljava/lang/Long;"); - } else if (type == Type.FLOAT_TYPE) { v.invokestatic("java/lang/Float", "valueOf", "(F)Ljava/lang/Float;"); } diff --git a/compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt b/compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt new file mode 100644 index 00000000000..17f32a26fd5 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt @@ -0,0 +1,5 @@ +val a: Byte? = -1 +val b: Short? = -1 + +// 1 I2B +// 1 I2S \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java index 5be113df25d..d0db728e04e 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java @@ -113,6 +113,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { doTest("compiler/testData/codegen/bytecodeText/constants/byte.kt"); } + @TestMetadata("nullableByteAndShort.kt") + public void testNullableByteAndShort() throws Exception { + doTest("compiler/testData/codegen/bytecodeText/constants/nullableByteAndShort.kt"); + } + @TestMetadata("short.kt") public void testShort() throws Exception { doTest("compiler/testData/codegen/bytecodeText/constants/short.kt");