Fix bug in decompiler that causes expression statement containing || or && with side effects to be removed

This commit is contained in:
Alexey Andreev 2019-10-30 13:38:47 +03:00
parent 15be89a758
commit 6bfbd38e22
2 changed files with 14 additions and 0 deletions

View File

@ -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);
}
}
}

View File

@ -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()));