diff options
author | Bart Schaefer <schaefer@ipost.com> | 2021-04-18 13:58:09 -0700 |
---|---|---|
committer | Bart Schaefer <schaefer@ipost.com> | 2021-04-18 13:58:09 -0700 |
commit | 82ff9f24f170eea7daa935fdaa09ab75a2f277ff (patch) | |
tree | cef3fef19fbe032466fcfbe50b7b6aa0878300a5 /Src/builtin.c | |
parent | 56ccb4a975bc87dd10bbbd6a1cfc296d6e2203b4 (diff) | |
download | zsh-82ff9f24f170eea7daa935fdaa09ab75a2f277ff.tar.gz zsh-82ff9f24f170eea7daa935fdaa09ab75a2f277ff.tar.xz zsh-82ff9f24f170eea7daa935fdaa09ab75a2f277ff.zip |
48560: add TYPESET_TO_UNSET option to remove initialization of parameters
Changes typeset such that ${newparam-notset} yields "notset" and "typeset -p newparam" does not show an assignment to the parameter. This is similar to the default behavior of bash and ksh, with minor differences in typeset output. Also add tests for some POSIX incompatibilities plus minor changes for test harness robustness.
Diffstat (limited to 'Src/builtin.c')
-rw-r--r-- | Src/builtin.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Src/builtin.c b/Src/builtin.c index 26335a2e8..6d119f7a5 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2491,6 +2491,8 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), return NULL; } } + if (isset(TYPESETTOUNSET)) + pm->node.flags |= PM_DEFAULTED; } else { if (idigit(*pname)) zerrnam(cname, "not an identifier: %s", pname); @@ -2836,7 +2838,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) unqueue_signals(); return 1; } else if (pm) { - if (!(pm->node.flags & PM_UNSET) + if ((!(pm->node.flags & PM_UNSET) || pm->node.flags & PM_DECLARED) && (locallevel == pm->level || !(on & PM_LOCAL))) { if (pm->node.flags & PM_TIED) { if (PM_TYPE(pm->node.flags) != PM_SCALAR) { @@ -2889,6 +2891,8 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) * * Don't attempt to set it yet, it's too early * to be exported properly. + * + * This may create the array with PM_DEFAULTED. */ asg2.name = asg->name; asg2.flags = 0; @@ -2930,8 +2934,12 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func) if (asg->value.array) { int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0; assignaparam(asg->name, zlinklist2array(asg->value.array, 1), flags); - } else if (oldval) - assignsparam(asg0.name, oldval, 0); + } else if (asg0.value.scalar || oldval) { + /* We have to undo what we did wrong with asg2 */ + apm->node.flags &= ~PM_DEFAULTED; + if (oldval) + assignsparam(asg0.name, oldval, 0); + } unqueue_signals(); return 0; |