JS backend: fix compiler crash on empty then if block

#EA-68941 fixed
This commit is contained in:
Zalim Bashorov
2015-06-01 19:01:00 +03:00
parent 779a0373c7
commit f90df7aa35
3 changed files with 16 additions and 4 deletions
@@ -41,4 +41,8 @@ public class IfExpressionTest extends AbstractExpressionTest {
public void testNestedIf() throws Exception {
checkFooBoxIsOk();
}
public void testWithEmptyBlocks() throws Exception {
checkFooBoxIsOk();
}
}
@@ -215,12 +215,12 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
boolean isKotlinExpression = BindingContextUtilPackage.isUsedAsExpression(expression, context.bindingContext());
JetExpression thenExpression = expression.getThen();
assert thenExpression != null : "then expression should not be null: " + expression.getText();
JetExpression elseExpression = expression.getElse();
JsStatement thenStatement = Translation.translateAsStatementAndMergeInBlockIfNeeded(thenExpression, context);
JsStatement elseStatement = (elseExpression != null) ? Translation.translateAsStatementAndMergeInBlockIfNeeded(elseExpression,
context) : null;
JsStatement thenStatement =
thenExpression != null ? Translation.translateAsStatementAndMergeInBlockIfNeeded(thenExpression, context) : null;
JsStatement elseStatement =
elseExpression != null ? Translation.translateAsStatementAndMergeInBlockIfNeeded(elseExpression, context) : null;
if (isKotlinExpression) {
JsExpression jsThenExpression = JsAstUtils.extractExpressionFromStatement(thenStatement);
@@ -0,0 +1,8 @@
package foo
fun box(): String {
var r = ""
if (r != "") else r += "O"
if (r == "O") r += "K" else;
return r
}