Reviewers: Lex,

Description:
Fixing division by zero while evaluating constant expression.


Please review this at http://gwt-code-reviews.appspot.com/435801/show

Affected files:
M dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java M dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java


Index: dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java
===================================================================
--- dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java (revision 8015) +++ dev/core/src/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluator.java (working copy)
@@ -133,7 +133,11 @@
         case SUB:
           return new JIntLiteral(x.getSourceInfo(), a - b);
         case DIV:
-          return new JIntLiteral(x.getSourceInfo(), a / b);
+          if (b != 0) {
+            return new JIntLiteral(x.getSourceInfo(), a / b);
+          } else {
+            return null;
+          }
         case EQ:
           return JBooleanLiteral.get(a == b);
         case NEQ:
Index: dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java
===================================================================
--- dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java (revision 8015) +++ dev/core/test/com/google/gwt/dev/jjs/impl/gflow/constants/ExpressionEvaluatorTest.java (working copy)
@@ -69,6 +69,9 @@
     assertThat("1 + i", "int", "int i; i = 1;").evaluatesInto("<null>");
     assertThat("2 + i", "int", "int i = 1;").evaluatesInto("3");
     assertThat("i + 3", "int", "int i = 1;").evaluatesInto("4");
+    assertThat("i / 2", "int", "int i = 6;").evaluatesInto("3");
+    assertThat("i / 0", "int", "int i = 1;").evaluatesInto("<null>");
+    assertThat("4 / 0", "int", "int i = 0;").evaluatesInto("<null>");
   }

   private static class Result {


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to