mainThe GNU Bourne-Again SHell - Support: sr #110228, Cannot shadow a local -r variable...

 
 

sr #110228: Cannot shadow a local -r variable when assigning a shadowing local to an array in its declaration

Submitter:  Ross Goldberg <ross>
Submitted:  Mon 27 Apr 2020 02:57:19 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 06 May 2020 02:45:31 PM UTC, comment #1: 

There is a fix for this in the devel branch.

Chet Ramey <chet>
Group administrator
Mon 27 Apr 2020 02:57:19 AM UTC, original submission:  

Description:
Cannot shadow a local -r variable when assigning a shadowing local to an array in its declaration.

i.e. 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.

Config info at end of post.

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


Config Info:
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


Ross Goldberg <ross>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by ross (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-05-06 chet StatusNone Done

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code