diff --git a/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java b/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java index 74146a144..1c30d56d1 100644 --- a/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java +++ b/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java @@ -16,6 +16,8 @@ package org.teavm.ast.optimization; import java.util.List; +import org.teavm.ast.BinaryExpr; +import org.teavm.ast.BinaryOperation; import org.teavm.ast.ConditionalExpr; import org.teavm.ast.ConditionalStatement; import org.teavm.ast.InvocationExpr; @@ -47,4 +49,13 @@ public class ExpressionSideEffectDecomposer extends RecursiveVisitor { public void visit(NewExpr expr) { target.add(Statement.assign(null, expr)); } + + @Override + public void visit(BinaryExpr expr) { + if (expr.getOperation() == BinaryOperation.AND || expr.getOperation() == BinaryOperation.OR) { + target.add(Statement.assign(null, expr)); + } else { + super.visit(expr); + } + } } diff --git a/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java b/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java index d81b770e0..f1f421c59 100644 --- a/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java +++ b/core/src/main/java/org/teavm/ast/optimization/OptimizingVisitor.java @@ -766,6 +766,9 @@ class OptimizingVisitor implements StatementVisitor, ExprVisitor { private void normalizeConditional(ConditionalStatement stmt) { if (stmt.getConsequent().isEmpty()) { + if (stmt.getAlternative().isEmpty()) { + return; + } stmt.getConsequent().addAll(stmt.getAlternative()); stmt.getAlternative().clear(); stmt.setCondition(ExprOptimizer.invert(stmt.getCondition()));