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,9 +234,11 @@ public abstract class StackValue {
} }
} }
else if (toType.equals(JET_UNIT_TYPE)) { else if (toType.equals(JET_UNIT_TYPE)) {
if (!fromType.equals(getType(Void.class))) {
pop(v, fromType); pop(v, fromType);
putUnitInstance(v); putUnitInstance(v);
} }
}
else if (toType.getSort() == Type.ARRAY) { else if (toType.getSort() == Type.ARRAY) {
v.checkcast(toType); v.checkcast(toType);
} }
@@ -431,10 +433,8 @@ public abstract class StackValue {
v.aconst(value); v.aconst(value);
} }
if (value != null) {
coerceTo(type, v); coerceTo(type, v);
} }
}
@Override @Override
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) { public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
@@ -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"); 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") @TestMetadata("unitClassObject.kt")
public void testUnitClassObject() throws Exception { public void testUnitClassObject() throws Exception {
doTest("compiler/testData/codegen/box/unit/unitClassObject.kt"); doTest("compiler/testData/codegen/box/unit/unitClassObject.kt");