JS backend: fix translation for || and && (create new tmp variable if needed)
This commit is contained in:
+8
-2
@@ -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 = ""
|
||||
|
||||
Reference in New Issue
Block a user