Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16235
| From | Ross Goldberg <ross.goldberg@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Cannot shadow local -r when assigning local to array in declaration |
| Date | 2020-04-23 20:02 -0400 |
| Message-ID | <mailman.1062.1587687695.3066.bug-bash@gnu.org> (permalink) |
| References | <CAAEcvMqof2+-vLwd_qrQYuVdcz497nr3hKdd5Kc0333Ygw5hVQ@mail.gmail.com> |
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin19.3.0
Compiler: clang
Compilation CFLAGS: -DSSH_SOURCE_BASHRC -Wno-parentheses
-Wno-format-security
uname output: Darwin Thrawn.local 19.4.0 Darwin Kernel Version 19.4.0: Wed
Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin19.3.0
Bash Version: 5.0
Patch Level: 16
Release Status: release
Description:
If a function, f, declares a local readonly variable, v, using local -r, an
error occurs if f calls another function, g, that declares its own local
variable v (therefore shadowing v from f) and that assigns v to an array in
the same statement as the shadowing declaration.
g can, however, assign v to a scalar in a shadowing declaration.
g can also assign a shadowing v to an array, as long as it isn't assigned
in the same statement as the declaration.
Repeat-By:
function aaa() {
local x='1 2 3'
echo "aaa ${x}"
}
function bbb() {
local x
x=(4 5 6)
echo "bbb ${x[*]}"
}
function ccc() {
local x=(7 8 9)
echo "ccc ${x[*]}"
}
function ddd() {
local -r x='0'
echo "ddd ${x}"
aaa
bbb
ccc
}
ddd
# the above outputs the following:
ddd 0
aaa 1 2 3
bbb 4 5 6
bash: x: readonly variable
Back to gnu.bash.bug | Previous | Next | Find similar
Cannot shadow local -r when assigning local to array in declaration Ross Goldberg <ross.goldberg@gmail.com> - 2020-04-23 20:02 -0400
csiph-web