diff options
author | Bart Schaefer <schaefer@zsh.org> | 2023-07-26 20:15:21 -0700 |
---|---|---|
committer | Bart Schaefer <schaefer@zsh.org> | 2023-07-26 20:15:21 -0700 |
commit | baa19d2a85758d6b6bcbcd8b78f065a3be262fb3 (patch) | |
tree | c761737950b1b241b52345e6267dc25faad2bebf /Src/params.c | |
parent | 5ff23c2c6db430398b0421c61fea11e8202c281a (diff) | |
download | zsh-baa19d2a85758d6b6bcbcd8b78f065a3be262fb3.tar.gz zsh-baa19d2a85758d6b6bcbcd8b78f065a3be262fb3.zip |
51945: assorted documentation improvements, bug fixes, and new test
1) Document the behavior of "typeset -n existing_var" (via Jun T. comment)
2) Prohibit "typeset -nm pattern" because, well, it's insane. Add test.
3) Improve doc for ${(!)ref} including ${{t!)ref} (Jun T.)
4) Fix doc for how-to unset of a named ref (Jun T.)
5) Allow "typeset +r -n ref" and "typeset +r +n ref" (Jun T.)
6) Fix "typeset -r -n ref=param" to create readonly references
7) Avoid accidental removal of PM_UNSET flag (Jun T.) and update test
8) Fix "typeset -gn ref=value" and add a test for it
9) Add tests for read-only reference behavior
10) Fix infinite recursion when resolving scope of an unset local
named reference, add test.
Diffstat (limited to 'Src/params.c')
-rw-r--r-- | Src/params.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Src/params.c b/Src/params.c index f5750a4b4..5841308d7 100644 --- a/Src/params.c +++ b/Src/params.c @@ -546,7 +546,7 @@ getparamnode(HashTable ht, const char *nam) } } - if (hn && ht == realparamtab) + if (hn && ht == realparamtab && !(hn->flags & PM_UNSET)) hn = resolve_nameref((Param)hn, NULL); return hn; } @@ -3729,7 +3729,9 @@ unsetparam_pm(Param pm, int altflag, int exp) char *altremove; if ((pm->node.flags & PM_READONLY) && pm->level <= locallevel) { - zerr("read-only variable: %s", pm->node.nam); + zerr("read-only %s: %s", + (pm->node.flags & PM_NAMEREF) ? "reference" : "variable", + pm->node.nam); return 1; } if ((pm->node.flags & PM_RESTRICTED) && isset(RESTRICTED)) { @@ -6182,8 +6184,12 @@ resolve_nameref(Param pm, const Asgment stop) seek = refname; } } - else if (pm && !(stop && (stop->flags & PM_NAMEREF))) - return (HashNode)pm; + else if (pm) { + if (!(stop && (stop->flags & PM_NAMEREF))) + return (HashNode)pm; + if (!(pm->node.flags & PM_NAMEREF)) + return (pm->level < locallevel ? NULL : (HashNode)pm); + } if (seek) { queue_signals(); /* pm->width is the offset of any subscript */ |