Skip to content

Commit

Permalink
[word_eval] Fix the ${!prefix@} failure for the second time (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga authored Mar 15, 2020
1 parent 30211bf commit 3a18432
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ def _EvalBracedVarSub(self, part, part_vals, quoted):
e_die("Array %r can't be referred to as a scalar (without @ or *)",
var_name, part=part)

suffix_processed = False
if part.prefix_op:
val = self._EmptyStrOrError(val) # maybe error

Expand All @@ -928,7 +929,7 @@ def _EvalBracedVarSub(self, part, part_vals, quoted):
# "${!prefix@}" is the only one that doesn't decay
maybe_decay_array = not (quoted and suffix_op.op_id == Id.VOp3_At)

part.suffix_op = None # don't process it later
suffix_processed = True
else:
# could be
# - ${!ref-default}
Expand All @@ -939,7 +940,7 @@ def _EvalBracedVarSub(self, part, part_vals, quoted):
# NOTE: The length operator followed by a suffix operator is a SYNTAX
# error.

if part.suffix_op:
if part.suffix_op and not suffix_processed:
op = part.suffix_op
UP_op = op
with tagswitch(op) as case:
Expand Down
13 changes: 12 additions & 1 deletion spec/var-op-bash.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@ argv.py ${!Z*}
argv.py ${!Z@}
argv.py "${!Z*}"
argv.py "${!Z@}"
for i in 1 2; do argv.py ${!Z*} ; done
for i in 1 2; do argv.py ${!Z@} ; done
for i in 1 2; do argv.py "${!Z*}"; done
for i in 1 2; do argv.py "${!Z@}"; done
## STDOUT:
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z ZIP ZOO ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z ZIP ZOO ZOOM']
['Z ZIP ZOO ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
['Z', 'ZIP', 'ZOO', 'ZOOM']
## END

0 comments on commit 3a18432

Please sign in to comment.