On 5/22/16 6:06 PM, Grisha Levit wrote:

> The expansion part really seems like the bug here, and can be demonstrated
> without any crazy cross-scope chains.
> 
> As I understand it, the intention is indeed to allow namerefs to point to
> outer-scope variables, even if they happen to have the same name as the
> reference, since a function like
> 
> |add_X() { local -n ref=$1; ref+=X; } |
> 
> works correctly even if it is passed |ref| as the argument:

That was the original intent, but I am now reconsidering it.  ksh93 doesn't
seem to allow nameref self-references at all, and I am thinking about
whether or not that is the best way to avoid problems like this.

> |$ ref=; add_X ref; echo "$ref" X |
> 
> However, if we try to access |$ref| inside the function, we get an error,
> though the += operation works just fine:
> 
> |$ add_X_echo() { local -n ref=$1; ref+=X; echo "$ref"; } $ ref=;
> add_X_echo; echo "$ref" bash: warning: ref: circular name reference X |

Should the assignment work?  I'm considering changing the assignments to
work more like the references.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to