Skip to content

Commit

Permalink
Add location info to string -> integer conversion errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Chu committed Sep 27, 2018
1 parent 993685c commit 5a9fb6a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/expr_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def __init__(self, mem, exec_opts, word_ev):
self.exec_opts = exec_opts
self.word_ev = word_ev # type: word_eval.WordEvaluator

def _StringToIntegerOrError(self, s):
def _StringToIntegerOrError(self, s, word=None):
try:
i = _StringToInteger(s)
i = _StringToInteger(s, word=word)
except util.FatalRuntimeError as e:
if self.exec_opts.strict_arith:
raise
Expand Down Expand Up @@ -409,7 +409,7 @@ def Eval(self, node, int_coerce=True):
return 0 # If not fatal, return 0

assert isinstance(item, str), item
return self._StringToIntegerOrError(item)
return self._StringToIntegerOrError(item, word=lhs)

if op_id == Id.Arith_Comma:
return rhs
Expand Down Expand Up @@ -612,8 +612,8 @@ def Eval(self, node):
if arg_type == bool_arg_type_e.Int:
# NOTE: We assume they are constants like [[ 3 -eq 3 ]].
# Bash also allows [[ 1+2 -eq 3 ]].
i1 = self._StringToIntegerOrError(s1)
i2 = self._StringToIntegerOrError(s2)
i1 = self._StringToIntegerOrError(s1, word=node.left)
i2 = self._StringToIntegerOrError(s2, word=node.right)

if op_id == Id.BoolBinary_eq:
return i1 == i2
Expand Down

0 comments on commit 5a9fb6a

Please sign in to comment.