Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Up-scope named references, vs. ksh



On Fri, Mar 1, 2024 at 10:22 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> $ ./Src/zsh -c 'f() { typeset -n ref=$1; unset ref; local var=2; ref=3; }; typeset -A var; f var; echo $var'
> <empty>

That's an actual bug, regardless of the rest of this discussion.

diff --git a/Src/builtin.c b/Src/builtin.c
index 44dfed651..83144677b 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3932,8 +3932,14 @@ bin_unset(char *name, char **argv, Options ops, int func)
            }
        } else {
            if (!OPT_ISSET(ops,'n')) {
+               int ref = (pm->node.flags & PM_NAMEREF);
                if (!(pm = (Param)resolve_nameref(pm, NULL)))
                    continue;
+               if (ref && pm->level < locallevel) {
+                   /* Just mark unset, do not remove from table */
+                   pm->node.flags |= PM_DECLARED|PM_UNSET;
+                   continue;
+               }
            }
            if (unsetparam_pm(pm, 0, 1))
                returnval = 1;




Messages sorted by: Reverse Date, Date, Thread, Author