Fix casts of Unit value to other types
This commit is contained in:
@@ -3744,9 +3744,10 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
value.put(boxType(value.type), v);
|
||||
|
||||
if (value.type == Type.VOID_TYPE) {
|
||||
v.aconst(null);
|
||||
StackValue.putUnitInstance(v);
|
||||
}
|
||||
else if (opToken != JetTokens.AS_SAFE) {
|
||||
|
||||
if (opToken != JetTokens.AS_SAFE) {
|
||||
if (!TypeUtils.isNullableType(rightType)) {
|
||||
v.dup();
|
||||
Label nonnull = new Label();
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
println(":Hi!") as Any
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = println(":Hi!") as Any
|
||||
if (x != Unit) return "Fail: $x"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = println(":Hi!") as? Any
|
||||
if (x != Unit) return "Fail: $x"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
foo() as Int?
|
||||
}
|
||||
catch (e: ClassCastException) {
|
||||
return "OK"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "Fail: ClassCastException should have been thrown, but was instead ${e.javaClass.getName()}: ${e.getMessage()}"
|
||||
}
|
||||
|
||||
return "Fail: no exception was thrown"
|
||||
}
|
||||
+12
-6
@@ -829,12 +829,6 @@ 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");
|
||||
@@ -889,6 +883,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unitAsAny.kt")
|
||||
public void testUnitAsAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/unitAsAny.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unitAsSafeAny.kt")
|
||||
public void testUnitAsSafeAny() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/unitAsSafeAny.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unitNullableCast.kt")
|
||||
public void testUnitNullableCast() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/unitNullableCast.kt");
|
||||
|
||||
+6
@@ -888,6 +888,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/casts/asWithGeneric.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unitAsInt.kt")
|
||||
public void testUnitAsInt() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/casts/unitAsInt.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/classes")
|
||||
|
||||
Reference in New Issue
Block a user