Fix for KT-6196: ClassCastException on unit property initializer

#KT-6196 Fixed
This commit is contained in:
Michael Bogdanov
2014-11-05 14:01:42 +03:00
parent 78bc15222b
commit ad6afee53f
3 changed files with 38 additions and 2 deletions
@@ -1209,8 +1209,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return StackValue.none();
}
else {
Type type = expressionType(expression);
Type targetType = type.equals(UNIT_TYPE) ? type : OBJECT_TYPE;
Type targetType = expressionType(ifExpression);
gen(expression, targetType);
@@ -0,0 +1,31 @@
class A (val p: String, p1: String, p2: String) {
var cond1: String = ""
var cond2: String = ""
val prop1 = if (cond1(p)) p1
val prop2 = if (cond2(p)) else;
fun cond1(p: String): Boolean {
cond1 = "cond1"
return p == "test"
}
fun cond2(p: String): Boolean {
cond2 = "cond2"
return p == "test"
}
}
fun box(): String {
val a = A("test", "OK", "fail")
if (a.cond1 != "cond1") return "fail 2 : ${a.cond1}"
if (a.cond2 != "cond2") return "fail 3 : ${a.cond2}"
return "OK"
}
@@ -6837,6 +6837,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("ifElse.kt")
public void testIfElse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/unit/ifElse.kt");
doTest(fileName);
}
@TestMetadata("kt3634.kt")
public void testKt3634() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/unit/kt3634.kt");