Hi, amending the previous approach; please find the attached patch: the global namerefs are followed, and resolved in the function scope. It works as follows:
bash-4.4$ typeset -n v=w; typeset -n w=x; typeset -n x=v; x=4 bash: warning: x: circular name reference. bash-4.4$ declare -n ref="HOME"; declare -n ref2=ref; f() { declare -n ref2="$1"; echo $ref2; }; f ref2; bash: declare: warning: ref2: circular name reference bash: warning: ref2: circular name reference /Users/merlin bash-4.4$ function bug { typeset -n var="$1"; printf "%s\n" "$var"; }; var="hello"; bug var; bash: typeset: warning: var: circular name reference bash: warning: var: circular name reference hello I have no idea what it breaks, I know it does not break the tests, and tries to address the reported issue. Please review. cheers, pg
find_variable_nameref_follows_global_nameref_patch.diff
Description: Binary data
On 10 Aug 2016, at 18:06, Andreas Kusalananda Kähäri wrote: > Configuration Information [Automatically generated, do not change]: > Machine: x86_64 > OS: openbsd6.0 > Compiler: cc > Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' > -DCONF_OSTYPE='openbsd6.0' -DCONF_MACHTYPE='x86_64-unknown-openbsd6.0' > -DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale' > -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib > -DUSE_MKTEMP -DUSE_MKSTEMP -I/usr/local/include -O2 -pipe > uname output: OpenBSD uerfale 6.0 GENERIC.MP#38 amd64 > Machine Type: x86_64-unknown-openbsd6.0 > > Bash Version: 4.3 > Patch Level: 46 > Release Status: release > > Description: > When declaring a variable in a function as a nameref, it can not > be dereferenced if the variable it's a nameref to happen to have > the same name as the nameref itself. This imposes unnecessary > restrictions on the caller. > > Also seen in GNU bash, version 4.3.39(1)-release (x86_64-apple-darwin15). > > Repeat-By: > function bug { > typeset -n var="$1" > printf "%s\n" "$var" > } > > var="hello" > bug var > > Result: > bash: warning: var: circular name reference > > Expected result: The string "hello" outputted with a terminating > newline (as with ksh93). >