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) {
|
public Unit invoke(InstructionAdapter v) {
|
||||||
value.put(boxType(value.type), 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)) {
|
if (!TypeUtils.isNullableType(rightType)) {
|
||||||
v.dup();
|
v.dup();
|
||||||
Label nonnull = new Label();
|
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);
|
v.mark(nonnull);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value.type == Type.VOID_TYPE) {
|
|
||||||
v.aconst(null);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
v.dup();
|
v.dup();
|
||||||
generateInstanceOfInstruction(rightType);
|
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);
|
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")
|
@TestMetadata("asForConstants.kt")
|
||||||
public void testAsForConstants() throws Exception {
|
public void testAsForConstants() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/asForConstants.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/asForConstants.kt");
|
||||||
@@ -914,6 +920,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("castGenericNull.kt")
|
||||||
public void testCastGenericNull() throws Exception {
|
public void testCastGenericNull() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/castGenericNull.kt");
|
||||||
@@ -926,6 +938,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("notIs.kt")
|
||||||
public void testNotIs() throws Exception {
|
public void testNotIs() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/notIs.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/notIs.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user