Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[word_eval] Fix the ${!prefix@} failure for the second time #657

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,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 @@ -927,7 +928,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 @@ -938,7 +939,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