[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bash-bug
Subject:    Re: declare [-+]n behavior on existing (chained) namerefs
From:       Piotr Grzybowski <narsil.pl () gmail ! com>
Date:       2016-04-30 23:10:05
Message-ID: 03D6FC23-5417-4CC3-8D66-3559C53FA87A () gmail ! com
[Download RAW message or body]


 after discussion with Grisha, the reason to different behaviour between:

f() { declare -n ref=var; declare -n ref; declare -p ref; }; f

and

f() { local var; declare -n ref=var; declare -n ref; declare -p ref; }; f

is:

in function context declare built-in always calls make_local_variable. this routine \
has no idea that the second declare re-declares already declared reference, and calls \
make_new_variable. the difference is: make_local_variable will not create a local \
variable when there is already one, hence everything seems fine. make_local_variable \
should check find_variable_noref(name) and act accordingly.  It seems half-intended.

pg

On 30 Apr 2016, at 22:24, Grisha Levit wrote:

> I just re-built bash-20160415 snapshot and am observing the same behavior.  To \
> clarify, the first case is the unexpected one -- shouldn't `declare -n ref=var; \
> declare -n ref' be a no-op, no matter if $var is set or not?  It is a no-op when in \
> global scope, but not inside a function.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic