[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: |
Mon, 2 May 2016 19:55:18 +0200 |
Hi,
I hope the attached patch does not break to much; it addresses the masking:
> declare -nt r=a; f() { declare a; declare -n r=a; declare -p a r; }; f
as per Grisha's report; it tries to enlighten make_local_variable to the
existence of nameref by returning existing local nameref in scope (declare -n
r=PATH; declare -n r; returns r with value of PATH) and by (hopefully)
correctly making existing nameref take precedence over the dereferenced value.
Would you please consider it?
cheers,
pg
masking_nameref_with_local_vars.patch
Description: Binary data
On 29 Apr 2016, at 03:49, Grisha Levit wrote:
> There is also an issue when doing something like `declare -n r=a' in a
> function if the same has been done in a higher scope. Instead of creating a
> new variable r in the function's scope, it modifies the local `a' to be a
> self-referencing nameref..
>
> $ declare -nt r=a; f() { declare a; declare -n r=a; declare -p a r; }; f
> declare -n a="a" # ??
> declare -nt r="a" # note the -t. this is the outer $r, a new one was not
> created
>
> In a slightly different version, with `declare -n r; r=a', the function exits
> with code 1 after the `r=a' statement:
>
> $ declare -nt r=a; f() { declare a; declare -n r; r=a; declare -p a r; }; f;
> echo $?
> 1
- Re: declare [-+]n behavior on existing (chained) namerefs,
Piotr Grzybowski <=