Skip to content

Commit

Permalink
[errors] Fix error location for arith_expr.VarRef.
Browse files Browse the repository at this point in the history
This code path was tickled by ble.sh.

Addresses issue #664.

Also turn off warnings since they come up too much.  #598 to provide
strictness levels could help.
  • Loading branch information
Andy Chu committed Mar 21, 2020
1 parent b390ccd commit 017f7a9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions frontend/location.py
Expand Up @@ -13,7 +13,7 @@
command__DoGroup, command__BraceGroup, command__Subshell,
command__WhileUntil, command__If, command__Case, command__TimeBlock,

arith_expr_e, arith_expr_t, arith_expr__ArithWord,
arith_expr_e, arith_expr_t, arith_expr__ArithWord, arith_expr__VarRef
)
from asdl import runtime
from core.util import log
Expand Down Expand Up @@ -70,8 +70,8 @@ def SpanForArithExpr(node):
UP_node = node
with tagswitch(node) as case:
if case(arith_expr_e.VarRef):
# TODO: VarRef should store a token instead of a string!
return runtime.NO_SPID
node = cast(arith_expr__VarRef, UP_node)
return node.token.span_id
elif case(arith_expr_e.ArithWord):
node = cast(arith_expr__ArithWord, UP_node)
return word_.LeftMostSpanForWord(node.w)
Expand Down
5 changes: 1 addition & 4 deletions osh/sh_expr_eval.py
Expand Up @@ -363,7 +363,7 @@ def _ValToIntOrError(self, val, span_id=runtime.NO_SPID):

elif case(value_e.Str):
val = cast(value__Str, UP_val)
return _StringToInteger(val.s, span_id=span_id) # calls e_die
return _StringToInteger(val.s, span_id=span_id) # calls e_strict

elif case(value_e.Obj):
# Note: this handles var x = 42; echo $(( x > 2 )).
Expand All @@ -377,8 +377,6 @@ def _ValToIntOrError(self, val, span_id=runtime.NO_SPID):
if self.exec_opts.strict_arith():
raise
else:
span_id = word_.SpanIdFromError(e)
self.errfmt.PrettyPrintError(e, prefix='warning: ')
return 0

# Arrays and associative arrays always fail -- not controlled by
Expand Down Expand Up @@ -744,7 +742,6 @@ def _StringToIntegerOrError(self, s, blame_word=None):
if self.always_strict or self.exec_opts.strict_arith():
raise
else:
self.errfmt.PrettyPrintError(e, prefix='warning: ')
i = 0
return i

Expand Down

0 comments on commit 017f7a9

Please sign in to comment.