Skip to content

Commit

Permalink
[fix] Fix type query ${var@a} when shopt -s compat_array
Browse files Browse the repository at this point in the history
Fixes issue tickled by ble.sh, mentioned in #1069.
  • Loading branch information
Andy C committed Jan 12, 2022
1 parent d5509b8 commit 9559c8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,15 +1136,15 @@ def _EvalBracketOp(self, val, part, quoted, vsub_state, vtest_place):

else: # no bracket op
var_name = vtest_place.name
if var_name and val.tag_() in (value_e.MaybeStrArray, value_e.AssocArray):
if (var_name and val.tag_() in (value_e.MaybeStrArray, value_e.AssocArray) and
not vsub_state.is_type_query):
if ShouldArrayDecay(var_name, self.exec_opts,
not (part.prefix_op or part.suffix_op)):
# for ${BASH_SOURCE}, etc.
val = DecayArray(val)
else:
if not vsub_state.is_type_query:
e_die("Array %r can't be referred to as a scalar (without @ or *)",
var_name, part=part)
e_die("Array %r can't be referred to as a scalar (without @ or *)",
var_name, part=part)

return val

Expand Down
13 changes: 13 additions & 0 deletions spec/ble-features.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,16 @@ argv.py ${d['0']} ${d['foo']} ${d['bar']}
## N-I dash/ash/yash/mksh stdout-json: ""

## N-I zsh stdout: ['1', 'hello', 'world']

#### [compat_array] ${alpha@a}
declare -A alpha=(['1']=2)
echo type=${alpha@a}
shopt -s compat_array
echo type=${alpha@a}
## STDOUT:
type=A
type=A
## END
## N-I mksh/zsh status: 1
## N-I dash/ash/yash status: 2
## N-I dash/ash/yash/mksh/zsh stdout-json: ""

0 comments on commit 9559c8a

Please sign in to comment.