Fix StackValue.coerce void to Object

We can only put Unit.VALUE on stack if we're requested an instance of Object or
Unit. In other cases (arbitrary objects / arrays) we put null instead
This commit is contained in:
Alexander Udalov
2013-04-22 12:13:58 +04:00
parent 36ddfaa24b
commit ace7bd9bc8
4 changed files with 46 additions and 1 deletions
@@ -230,9 +230,12 @@ public abstract class StackValue {
pop(fromType, v);
}
else if (fromType.getSort() == Type.VOID) {
if (toType.getSort() == Type.OBJECT) {
if (toType.equals(JET_UNIT_TYPE) || toType.equals(OBJECT_TYPE)) {
putUnitInstance(v);
}
else if (toType.getSort() == Type.OBJECT || toType.getSort() == Type.ARRAY) {
v.aconst(null);
}
else {
pushDefaultPrimitiveValueOnStack(toType, v);
}
@@ -0,0 +1,16 @@
fun a(): IntArray? = null
fun b() = throw Exception()
fun foo(): IntArray = a() ?: b()
fun box(): String {
try {
foo()
} catch (e: Exception) {
return "OK"
}
return "Fail"
}
@@ -0,0 +1,16 @@
fun a(): String? = null
fun b() = throw Exception()
fun foo(): String = a() ?: b()
fun box(): String {
try {
foo()
} catch (e: Exception) {
return "OK"
}
return "Fail"
}
@@ -1897,6 +1897,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/functions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("coerceVoidToArray.kt")
public void testCoerceVoidToArray() throws Exception {
doTest("compiler/testData/codegen/box/functions/coerceVoidToArray.kt");
}
@TestMetadata("coerceVoidToObject.kt")
public void testCoerceVoidToObject() throws Exception {
doTest("compiler/testData/codegen/box/functions/coerceVoidToObject.kt");
}
@TestMetadata("defaultargs.kt")
public void testDefaultargs() throws Exception {
doTest("compiler/testData/codegen/box/functions/defaultargs.kt");