Fix VerifyError for 'when' of type 'Unit?'

This commit is contained in:
Alexander Udalov
2013-12-10 21:07:05 +04:00
parent 0d9c126485
commit 00da5fe1fb
4 changed files with 39 additions and 5 deletions
@@ -234,8 +234,10 @@ public abstract class StackValue {
}
}
else if (toType.equals(JET_UNIT_TYPE)) {
pop(v, fromType);
putUnitInstance(v);
if (!fromType.equals(getType(Void.class))) {
pop(v, fromType);
putUnitInstance(v);
}
}
else if (toType.getSort() == Type.ARRAY) {
v.checkcast(toType);
@@ -431,9 +433,7 @@ public abstract class StackValue {
v.aconst(value);
}
if (value != null) {
coerceTo(type, v);
}
coerceTo(type, v);
}
@Override
@@ -0,0 +1,12 @@
fun foo() {}
fun box(): String {
when ("A") {
"B" -> foo()
else -> null
}
foo()
return "OK"
}
@@ -0,0 +1,12 @@
fun foo() {}
fun box(): String {
when ("A") {
"B" -> null
else -> foo()
}
foo()
return "OK"
}
@@ -4812,6 +4812,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/unit/nullableUnit.kt");
}
@TestMetadata("nullableUnitInWhen1.kt")
public void testNullableUnitInWhen1() throws Exception {
doTest("compiler/testData/codegen/box/unit/nullableUnitInWhen1.kt");
}
@TestMetadata("nullableUnitInWhen2.kt")
public void testNullableUnitInWhen2() throws Exception {
doTest("compiler/testData/codegen/box/unit/nullableUnitInWhen2.kt");
}
@TestMetadata("unitClassObject.kt")
public void testUnitClassObject() throws Exception {
doTest("compiler/testData/codegen/box/unit/unitClassObject.kt");