JS backend: fix translation for || and && (create new tmp variable if needed)

This commit is contained in:
Michael Nedzelsky
2014-09-02 16:45:21 +04:00
parent 40e5d6c8f5
commit 5967b6637f
2 changed files with 10 additions and 2 deletions
@@ -166,8 +166,14 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
return new JsBinaryOperation(operator, leftExpression, rightExpression);
}
assert rightExpression instanceof JsNameRef : "expected JsNameRef, but " + expression.getText();
JsNameRef result = (JsNameRef) rightExpression; // Reuse tmp variable
JsNameRef result;
if (rightExpression instanceof JsNameRef) {
result = (JsNameRef) rightExpression; // Reuse tmp variable
} else {
TemporaryVariable resultVar = context().declareTemporary(rightExpression);
result = resultVar.reference();
rightBlock.getStatements().add(resultVar.assignmentExpression().makeStmt());
}
JsIf ifStatement;
if (token.equals(JetTokens.ANDAND)) {
@@ -8,6 +8,8 @@ fun bar(s: String, value: Boolean): Boolean {
}
fun box(): String {
val a = if (true || if(bar("A", false)) {2} else {3} == 0) { }
assertEquals("", global)
// Simple || Simple
global = ""