generate more correct bytecode for casting Unit to other types
This commit is contained in:
@@ -3918,7 +3918,10 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
value.put(boxType(value.type), v);
|
||||
|
||||
if (opToken != JetTokens.AS_SAFE) {
|
||||
if (value.type == Type.VOID_TYPE) {
|
||||
v.aconst(null);
|
||||
}
|
||||
else if (opToken != JetTokens.AS_SAFE) {
|
||||
if (!TypeUtils.isNullableType(rightType)) {
|
||||
v.dup();
|
||||
Label nonnull = new Label();
|
||||
@@ -3931,9 +3934,6 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
v.mark(nonnull);
|
||||
}
|
||||
}
|
||||
else if (value.type == Type.VOID_TYPE) {
|
||||
v.aconst(null);
|
||||
}
|
||||
else {
|
||||
v.dup();
|
||||
generateInstanceOfInstruction(rightType);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
println(":Hi!") as Any
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun box() = if (4 as? Unit != null) "Fail" else "OK"
|
||||
@@ -0,0 +1,6 @@
|
||||
val foo: () -> Unit = {}
|
||||
|
||||
fun box(): String {
|
||||
foo() as Unit
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -890,6 +890,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asAny.kt")
|
||||
public void testAsAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/asAny.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asForConstants.kt")
|
||||
public void testAsForConstants() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/asForConstants.kt");
|
||||
@@ -914,6 +920,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("asUnit.kt")
|
||||
public void testAsUnit() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/asUnit.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("castGenericNull.kt")
|
||||
public void testCastGenericNull() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||
@@ -926,6 +938,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaToUnitCast.kt")
|
||||
public void testLambdaToUnitCast() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/lambdaToUnitCast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notIs.kt")
|
||||
public void testNotIs() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/notIs.kt");
|
||||
|
||||
Reference in New Issue
Block a user