Skip to content

Commit

Permalink
[errors] Two fixes for location info in word eval
Browse files Browse the repository at this point in the history
This is issue #2129

- Reset self.loc_for_expr on every line
  - the expression location is supposed to refine the line location
- Pass location info in Stringify(), so we don't need to use the
  fallback location
  • Loading branch information
Andy C committed Dec 11, 2024
1 parent a023e72 commit 4b256bc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,7 @@ def SetTokenForLine(self, tok):
#traceback.print_stack()
#return

self.loc_for_expr = loc.Missing # reset it on every line
self.token_for_line = tok

def SetLocationForExpr(self, blame_loc):
Expand Down
3 changes: 2 additions & 1 deletion frontend/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
loc,
loc_t,
loc_e,
loc_str,
command,
command_e,
command_t,
Expand Down Expand Up @@ -110,7 +111,7 @@ def TokenFor(loc_):
return None

else:
raise AssertionError()
raise AssertionError(loc_str(loc_.tag()))

raise AssertionError()

Expand Down
2 changes: 1 addition & 1 deletion osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _ValueToPartValue(val, quoted, part_loc):
# value_e.List is also here - we use val_ops.Stringify()s err message
elif case(value_e.Null, value_e.Bool, value_e.Int, value_e.Float,
value_e.Eggex, value_e.List):
s = val_ops.Stringify(val, loc.Missing, 'Word eval ')
s = val_ops.Stringify(val, loc.WordPart(part_loc), 'Word eval ')
return Piece(s, quoted, not quoted)

else:
Expand Down
17 changes: 17 additions & 0 deletions test/ysh-runtime-errors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,23 @@ test-int-overflow() {
_ysh-expr-error "= int('$neg')"
}

test-bug-2129() {
# bug in interactive only

_assert-sh-status 3 $YSH 'Should fail under YSH' \
-i -c '
proc p (...args) {
echo $args
}
p 1 2 3
echo $[{}]
p 1 2 3
'
}

soil-run-py() {
run-test-funcs
}
Expand Down

0 comments on commit 4b256bc

Please sign in to comment.