Build break fix; r2515 caused reordered if blocks with nested else-if chains to evaluate incorrectly.

Review by: spoon (TBR)


git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2526 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index 5f71339..a9def73 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -420,6 +420,10 @@
         // if (!cond) foo else bar -> if (cond) bar else foo
         JExpression unflipped = maybeUnflipBoolean(expr);
         if (unflipped != null) {
+          // Force sub-parts to blocks, otherwise we break else-if chains.
+          // TODO: this goes away when we normalize the Java AST properly.
+          thenStmt = ensureBlock(thenStmt);
+          elseStmt = ensureBlock(elseStmt);
           ctx.replaceMe(new JIfStatement(program, x.getSourceInfo(), unflipped,
               elseStmt, thenStmt));
           return;
@@ -757,6 +761,15 @@
       return true;
     }
 
+    private JStatement ensureBlock(JStatement stmt) {
+      if (!(stmt instanceof JBlock)) {
+        JBlock block = new JBlock(program, stmt.getSourceInfo());
+        block.statements.add(stmt);
+        stmt = block;
+      }
+      return stmt;
+    }
+
     private void evalConcat(JExpression lhs, JExpression rhs, Context ctx) {
       if (lhs instanceof JValueLiteral && rhs instanceof JValueLiteral) {
         Object lhsObj = ((JValueLiteral) lhs).getValueObj();