[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: declare [-+]n behavior on existing (chained) namerefs
From: |
Piotr Grzybowski |
Subject: |
Re: declare [-+]n behavior on existing (chained) namerefs |
Date: |
Sun, 1 May 2016 01:10:05 +0200 |
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.