Permalink
Browse files
Temporary fix divide by zero crash.
Exposed by a case in test/runtime-errors.sh
Add TODOs for a better fix.
- Loading branch information...
Showing
with
15 additions
and
3 deletions.
-
+14
−3
core/expr_eval.py
-
+1
−0
core/tdop.py
|
|
@@ -125,6 +125,8 @@ def _StringToIntegerOrError(self, s): |
|
|
raise
|
|
|
else:
|
|
|
i = 0
|
|
|
# TODO: Need the arena for printing this error?
|
|
|
#ui.PrettyPrintError(e)
|
|
|
warn(e.UserErrorString())
|
|
|
return i
|
|
|
|
|
|
@@ -394,10 +396,19 @@ def Eval(self, node): |
|
|
try:
|
|
|
return lhs / rhs
|
|
|
except ZeroDivisionError:
|
|
|
# TODO: Instead of op_id, I should have the token
|
|
|
# node.right.w crashes if it's not a constant!
|
|
|
e_die('Divide by zero', word=node.right.w)
|
|
|
# TODO: _ErrorWithLocation should also accept arith_expr ? I
|
|
|
# think I needed that for other stuff.
|
|
|
# Or I could blame the '/' token, instead of op_id.
|
|
|
error_expr = node.right # node is ArithBinary
|
|
|
if error_expr.tag == arith_expr_e.ArithVarRef:
|
|
|
# TODO: ArithVarRef should store a token instead of a string!
|
|
|
e_die('Divide by zero (name)')
|
|
|
elif error_expr.tag == arith_expr_e.ArithWord:
|
|
|
e_die('Divide by zero', word=node.right.w)
|
|
|
else:
|
|
|
e_die('Divide by zero')
|
|
|
if op_id == Id.Arith_Percent:
|
|
|
|
|
|
return lhs % rhs
|
|
|
if op_id == Id.Arith_DStar:
|
|
|
return lhs ** rhs
|
|
|
|
|
|
@@ -125,6 +125,7 @@ def LeftError(p, t, left, rbp): |
|
|
|
|
|
def LeftBinaryOp(p, w, left, rbp):
|
|
|
""" Normal binary operator like 1+2 or 2*3, etc. """
|
|
|
# TODO: w shoudl be a TokenWord, and we should extract the token from it.
|
|
|
return ast.ArithBinary(word.ArithId(w), left, p.ParseUntil(rbp))
|
|
|
|
|
|
|
|
|
|
0 comments on commit
e19cee4