Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14897
| Path | csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Grisha Levit <grishalevit@gmail.com> |
| Newsgroups | gnu.bash.bug |
| Subject | issues with nameref resolution loop in a function |
| Date | Sat, 8 Dec 2018 20:30:42 -0500 |
| Lines | 53 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.5411.1544319108.1284.bug-bash@gnu.org> (permalink) |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| X-Trace | usenet.stanford.edu 1544319109 24754 208.118.235.17 (9 Dec 2018 01:31:49 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| To | bug-bash <bug-bash@gnu.org> |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=stVGjoXzsRZ0NVdxGk1i7h0IXzPoIf0oPbsFztYGrRU=; b=AAYMvzaIcEPHaF7XtidUEYmmARoKDEW+AMCKUjNUi76FTej288FxzooaboE5ivmgqU /QKSy7UVn/nlD6KTEwfMQmBCJziFhCAtAM7DBuvxs5Mp50UnnBdl4pQr/Jn9XJGOfyn1 gZA2v+mbkiEZtMy4D8LGPA771j1KvV5u8QFlK+JXG6Po7+npi50bdoyqjnFlegg1bEyY wrMsK3HQ9LShVE19rnh+p8rCezDTBgYXHVIlwJTX5EE/rODg7/bzLsOQvhtY1H/eZRWa uJ61Jq7JW3fv0fZhpD+Xjr0SL8Ex4MF8HmOG7WB1OqySEFIEkTs5r/fUdvxjZvJ1y9Ln shrw== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=stVGjoXzsRZ0NVdxGk1i7h0IXzPoIf0oPbsFztYGrRU=; b=E+iTLj8cxI1aQza8Wl1rvHE5bYsPKAljzA/qB+tgcO1v5H6WWVrNUlojsszq/6l1vn +zcH+ep4alBpgb5EgY39n4YtXgzMzLRQ21Qqf2rkxm3BngquvVwANe68zBWqH2B9/6oQ AukuOP2/mFZX6ZJvkE6qrDucMsu7BDUXbe6hyariuSYH8TiTw8vJnJR09HV9Zf83jSB2 BEMRQXuxQMIERdxDfLS9gDe9DkaVaAVnqiEBKbB+Hb7FT8Cnp6V7Ia5pkDDbEGQwXwzg Qi3jCOz9HoYf9YrpzUQfLALIxR2HFB3V8Ho6smKukNHhfSeh9qnfAQ+B+3AzqDp7aDl6 NKUg== |
| X-Gm-Message-State | AA+aEWbsqGLSI3dpo7vG/HY2rhBU75cOAnhJUd5/9U+RLHwTogijnxqQ uT280s3WappgT+2+ZeINUslGxO35JAqytI1I0gUOwgCG |
| X-Google-Smtp-Source | AFSGD/W43Rk5p3KDh8Y3UVF4frmUEHrbpUmJ/v9tANI7gmgmJx/fDH30rXYFYEYmlq6o/SsVDxTNSjlVkENzPDtprmU= |
| X-Received | by 2002:ac8:1712:: with SMTP id w18mr7231277qtj.76.1544319052962; Sat, 08 Dec 2018 17:30:52 -0800 (PST) |
| X-detected-operating-system | by eggs.gnu.org: Genre and OS details not recognized. |
| X-Received-From | 2607:f8b0:4864:20::829 |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.21 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <http://lists.gnu.org/archive/html/bug-bash/> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| Xref | csiph.com gnu.bash.bug:14897 |
Show key headers only | View raw
There seems to be an issue with the following new bash-5.0 feature:
A nameref name resolution loop in a function now resolves to a variable by
that name in the global scope.
[ Note: "warning: x: circular name reference" messages omitted below. ]
While referencing such a nameref works as described, scalar assignment to it
modifies the variable from the next higher scope rather than the global one:
$ inner() { local -n x=x; x=3; }
$ outer() { local x=2; inner; declare -p x; }
$ x=1; outer; declare -p x
declare -- x="3" # x changed in outer()
declare -- x="1" # global x not changed
There is odd/broken behavior when `declare' is used to modify such a
variable,
similar to https://lists.gnu.org/archive/html/bug-bash/2018-07/msg00072.html
I think the right thing here would be for `declare' to act as if the `-g`
flag
had been supplied and modify the variable in the global scope?
$ f() { local -n x=x; declare x=(2); x=3; declare -p x; }
$ x=1; f; declare -p x
declare -an x=([0]="2") # local nameref borked
declare -- x="1" # global x not changed
$ f() { local -n x=x; declare x=2; }; f
-bash: declare: `2': invalid variable name for name reference
$ f() { local -n x=x; declare -a x=y; declare -p x; }
$ x=1; f; declare -p x
declare -an x=() # local nameref borked
declare -a x=([0]="y") # global x correct (?)
$ unset x; declare -p x
declare -- x="1" # original after unset
`unset' (no `-n') modifies the nameref:
$ f() { local -n x=x; unset x; declare -p x; }
$ x=1; f; declare -p x
declare -- x
declare -- x="1"
If the target is an array reference that results in a circular nameref,
then
neither referencing nor assigning to the nameref works:
$ f() { local -n x=x[0]; echo "<$x>"; x=2; }
$ x=1; f
<>
-bash: `x[0]': not a valid identifier
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
issues with nameref resolution loop in a function Grisha Levit <grishalevit@gmail.com> - 2018-12-08 20:30 -0500
csiph-web