If-then-else statements & correct line numbers
#KT-3036 Fixed
This commit is contained in:
@@ -362,7 +362,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
|
||||
/* package */ StackValue generateIfExpression(JetIfExpression expression, boolean isStatement) {
|
||||
Type asmType = expressionType(expression);
|
||||
Type asmType = isStatement ? Type.VOID_TYPE : expressionType(expression);
|
||||
StackValue condition = gen(expression.getCondition());
|
||||
|
||||
JetExpression thenExpression = expression.getThen();
|
||||
@@ -374,9 +374,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
if (isEmptyExpression(thenExpression)) {
|
||||
if (isEmptyExpression(elseExpression)) {
|
||||
if (!asmType.equals(JET_TUPLE0_TYPE)) {
|
||||
throw new CompilationException("Completely empty 'if' is expected to have Unit type", null, expression);
|
||||
}
|
||||
condition.put(asmType, v);
|
||||
return StackValue.onStack(asmType);
|
||||
}
|
||||
@@ -388,7 +385,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Label elseLabel = new Label();
|
||||
condition.condJump(elseLabel, true, v); // == 0, i.e. false
|
||||
|
||||
@@ -401,6 +397,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
gen(elseExpression, asmType);
|
||||
|
||||
markLineNumber(expression);
|
||||
v.mark(end);
|
||||
|
||||
return StackValue.onStack(asmType);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun z(b: Boolean) {}
|
||||
|
||||
fun foo(b: Boolean) {
|
||||
if (b) {
|
||||
z(b)
|
||||
} else {
|
||||
z(b)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
fun foo(b: Boolean) {
|
||||
if (b) {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo() {
|
||||
if (0 < 1) {
|
||||
System.out?.println()
|
||||
} else {
|
||||
System.out?.println()
|
||||
}
|
||||
|
||||
val b = if (1 < 2) {
|
||||
System.out?.println()
|
||||
} else {
|
||||
System.out?.println()
|
||||
}
|
||||
}
|
||||
|
||||
// 2 3 5 8 9 11 8
|
||||
@@ -299,6 +299,10 @@ public class LineNumberTest extends TestCaseWithTmpdir {
|
||||
doTestCustom();
|
||||
}
|
||||
|
||||
public void testIfThenElse() {
|
||||
doTestCustom();
|
||||
}
|
||||
|
||||
public void testStaticDelegate() {
|
||||
JetFile foo = createPsiFile("staticDelegate/foo.kt");
|
||||
JetFile bar = createPsiFile("staticDelegate/bar.kt");
|
||||
|
||||
@@ -40,4 +40,12 @@ public class StatementGenTest extends CodegenTestCase {
|
||||
public void testIfSingleBranch() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIfThenElse() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testIfThenElseEmpty() {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user