Skip to content

Commit 9559c8a

Browse files
author
Andy C
committed
[fix] Fix type query ${var@a} when shopt -s compat_array
Fixes issue tickled by ble.sh, mentioned in #1069.
1 parent d5509b8 commit 9559c8a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

osh/word_eval.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,15 +1136,15 @@ def _EvalBracketOp(self, val, part, quoted, vsub_state, vtest_place):
11361136

11371137
else: # no bracket op
11381138
var_name = vtest_place.name
1139-
if var_name and val.tag_() in (value_e.MaybeStrArray, value_e.AssocArray):
1139+
if (var_name and val.tag_() in (value_e.MaybeStrArray, value_e.AssocArray) and
1140+
not vsub_state.is_type_query):
11401141
if ShouldArrayDecay(var_name, self.exec_opts,
11411142
not (part.prefix_op or part.suffix_op)):
11421143
# for ${BASH_SOURCE}, etc.
11431144
val = DecayArray(val)
11441145
else:
1145-
if not vsub_state.is_type_query:
1146-
e_die("Array %r can't be referred to as a scalar (without @ or *)",
1147-
var_name, part=part)
1146+
e_die("Array %r can't be referred to as a scalar (without @ or *)",
1147+
var_name, part=part)
11481148

11491149
return val
11501150

spec/ble-features.test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,16 @@ argv.py ${d['0']} ${d['foo']} ${d['bar']}
629629
## N-I dash/ash/yash/mksh stdout-json: ""
630630

631631
## N-I zsh stdout: ['1', 'hello', 'world']
632+
633+
#### [compat_array] ${alpha@a}
634+
declare -A alpha=(['1']=2)
635+
echo type=${alpha@a}
636+
shopt -s compat_array
637+
echo type=${alpha@a}
638+
## STDOUT:
639+
type=A
640+
type=A
641+
## END
642+
## N-I mksh/zsh status: 1
643+
## N-I dash/ash/yash status: 2
644+
## N-I dash/ash/yash/mksh/zsh stdout-json: ""

0 commit comments

Comments
 (0)