Fix safe call

This commit is contained in:
Natalia Ukhorskaya
2013-12-12 17:11:41 +04:00
parent db8222c50a
commit 66effee8cd
3 changed files with 22 additions and 1 deletions
@@ -3565,7 +3565,7 @@ The "returned" value of try expression with no finally is either the last expres
DeclarationDescriptor descriptor = rightType.getConstructor().getDeclarationDescriptor();
if (descriptor instanceof ClassDescriptor || descriptor instanceof TypeParameterDescriptor) {
StackValue value = genQualified(receiver, left);
value.put(boxType(rightTypeAsm), v);
value.put(boxType(value.type), v);
if (opToken != JetTokens.AS_SAFE) {
if (!CodegenUtil.isNullableType(rightType)) {
@@ -0,0 +1,16 @@
class A
class B
fun box(): String {
val a = A()
a as? B
a as? B ?: "fail"
if ((A() as? B) != null) return "fail1"
if ((a as? B) != null) return "fail2"
val v = a as? B ?: "fail"
if (v != "fail") return "fail4"
return "OK"
}
@@ -733,6 +733,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/casts/asSafe.kt");
}
@TestMetadata("asSafeFail.kt")
public void testAsSafeFail() throws Exception {
doTest("compiler/testData/codegen/box/casts/asSafeFail.kt");
}
@TestMetadata("castGenericNull.kt")
public void testCastGenericNull() throws Exception {
doTest("compiler/testData/codegen/box/casts/castGenericNull.kt");