Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -Wno-parent heses -Wno-format-security uname output: Linux brlin-musicha-mz-530 5.4.0-52-generic #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu
Bash Version: 5.0 Patch Level: 17 Release Status: release Description: Example script reproducing the bug: ```bash #!/usr/bin/env bash # Depict the variable shadowing phenomenon # ./depict-the-variable-shadowing-phenomenon.bash set \ -o errexit \ -o errtrace \ -o nounset declare -r variable_shadowed='(Value to be shadowed in the function)' check_values_of_variables_in_different_scope(){ local -r variable_shadowed="Another value" printf 'In the %s context: \n' "${FUNCNAME[0]}" printf 'variable_shadowed = %s\n' "${variable_shadowed}" } check_values_of_variables_in_different_scope ``` ## Expected behavior ``` $ ./depict-the-variable-shadowing-phenomenon.bash In the check_values_of_variables_in_different_scope context: variable_shadowed = Another value ``` ## Current behavior ``` $ LANG=C ./depict-the-variable-shadowing-phenomenon.bash ./depict-the-variable-shadowing-phenomenon.bash: line 11: local: variable_shadowed: readonly variable ``` Repeat-By: Refer the "Descripton" section. Fix: I suggest that bash shouldn't trigger the error, if the variable to be set is a `different` variable instantiated by the variable shadowing mechanism.