Skip to content

Commit

Permalink
[errors] Remove unnecessary SetTokenForLine()
Browse files Browse the repository at this point in the history
It's only for $LINENO and the fallback.

Doesn't apply to ShFunction

    f() { echo hi; }

or

    proc p { echo hi }

Part of #1707

Should remove from 'if' too
  • Loading branch information
Andy C committed Aug 24, 2023
1 parent 5b68c12 commit df4afb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions osh/cmd_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,9 @@ def _Dispatch(self, node, cmd_st):

elif case(command_e.ControlFlow):
node = cast(command.ControlFlow, UP_node)

keyword = node.keyword
self.mem.SetTokenForLine(node.keyword)
self.mem.SetTokenForLine(keyword)

if node.arg_word: # Evaluate the argument
str_val = self.word_ev.EvalWordToString(node.arg_word)
Expand Down Expand Up @@ -1480,7 +1481,7 @@ def _Dispatch(self, node, cmd_st):

elif case(command_e.ShFunction):
node = cast(command.ShFunction, UP_node)
self.mem.SetTokenForLine(node.name_tok)

if node.name in self.procs and not self.exec_opts.redefine_proc_func(
):
e_die(
Expand All @@ -1494,7 +1495,6 @@ def _Dispatch(self, node, cmd_st):
elif case(command_e.Proc):
node = cast(command.Proc, UP_node)

self.mem.SetTokenForLine(node.name)
proc_name = lexer.TokenVal(node.name)
if proc_name in self.procs and not self.exec_opts.redefine_proc_func(
):
Expand Down
8 changes: 8 additions & 0 deletions test/runtime-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,14 @@ fallback_locations() {

_error-case 'if s=$(true) y=$(( 3 ** -2 )); then echo hi; fi'

_error-case 'shopt -s strict_arith; x=a; echo $(( x ))'
_error-case 'shopt -s strict_arith; x=a; echo $(( $x ))'
_error-case 'shopt -s strict_arith; x=a; [[ $x -gt 3 ]]'
_error-case 'shopt -s strict_arith; shopt -u eval_unsafe_arith; x=a; [[ $x -gt 3 ]]'

_error-case 'shopt -s strict_arith; x=0xgg; echo $(( x ))'


echo done
}

Expand Down

0 comments on commit df4afb9

Please sign in to comment.