summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Schaefer <schaefer@zsh.org>2026-07-26 20:31:35 -0700
committerBart Schaefer <schaefer@zsh.org>2026-07-26 20:58:50 -0700
commit25642451465f55d76acffe7eda1273e592e0aa78 (patch)
treed7e09543af0d9fc581b60a519f115bafd309ea06
parent54994: use gdbm_fd_open so we can move the fd to >9 (diff)
downloadzsh-25642451465f55d76acffe7eda1273e592e0aa78.tar
zsh-25642451465f55d76acffe7eda1273e592e0aa78.tar.gz
zsh-25642451465f55d76acffe7eda1273e592e0aa78.tar.bz2
zsh-25642451465f55d76acffe7eda1273e592e0aa78.tar.lz
zsh-25642451465f55d76acffe7eda1273e592e0aa78.tar.xz
zsh-25642451465f55d76acffe7eda1273e592e0aa78.tar.zst
zsh-25642451465f55d76acffe7eda1273e592e0aa78.zip
55030: allow "typeset -hn", issue error on useless no-op "typeset -gh"
Includes unposted K01nameref test
-rw-r--r--Src/builtin.c19
-rw-r--r--Test/B02typeset.ztst9
-rw-r--r--Test/K01nameref.ztst4
3 files changed, 23 insertions, 9 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index 2e3e5752a..79a7678ab 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2209,6 +2209,17 @@ typeset_single(char *cname, char *pname, Param pm, int func,
on |= PM_EXPORTED;
*/
}
+ if (usepm && (on & PM_HIDE) &&
+ (pm->node.flags & (PM_SPECIAL|PM_AUTOLOAD)) &&
+ pm->level <= locallevel) {
+#if 0
+ zwarnnam(cname, "%s: can't change parameter attribute", pname);
+ /* return NULL; */ /* this has always been a no-op */
+#else
+ zerrnam(cname, "%s: can't change parameter attribute", pname);
+ return NULL; /* this was previously a no-op */
+#endif
+ }
/*
* A parameter will be local if
@@ -2516,8 +2527,8 @@ typeset_single(char *cname, char *pname, Param pm, int func,
pm = createparam(pname, on & ~PM_READONLY);
if (!pm) {
if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z |
- PM_INTEGER | PM_EFLOAT | PM_FFLOAT))
- zerrnam(cname, "can't change variable attribute: %s", pname);
+ PM_INTEGER | PM_EFLOAT | PM_FFLOAT | PM_NAMEREF))
+ zerrnam(cname, "%s: can't change parameter attribute", pname);
return NULL;
}
if (on & (PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z)) {
@@ -2689,14 +2700,14 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
else
continue;
if (OPT_MINUS(ops,'n')) {
- if (bit & ~(PM_READONLY|PM_UPPER|PM_HIDEVAL)) {
+ if (bit & ~(PM_READONLY|PM_UPPER|PM_HIDEVAL|PM_HIDE)) {
zwarnnam(name, "-%c not allowed with -n", optval);
/* return 1; */
}
}
}
if (OPT_MINUS(ops,'n')) {
- if ((on|off) & ~(PM_READONLY|PM_UPPER|PM_HIDEVAL)) {
+ if ((on|off) & ~(PM_READONLY|PM_UPPER|PM_HIDEVAL|PM_HIDE)) {
/* zwarnnam(name, "no other attributes allowed with -n"); */
return 1;
}
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index fe9eb55eb..b45ad027f 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -1133,9 +1133,9 @@
echo v=${SRANDOM/<->/integer}
typeset -gh SRANDOM
echo v=${SRANDOM/<->/integer}
-0:Global -h variable doesn't hide special variable
->v=integer
+1:Global -h variable doesn't hide special variable
>v=integer
+?(eval):typeset:3: SRANDOM: can't change parameter attribute
zmodload -u zsh/random
echo v=${SRANDOM/<->/integer}
@@ -1168,10 +1168,9 @@
typeset -gh SRANDOM
echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}
echo v=${SRANDOM/<->/integer}
-0:Global -h variable doesn't hide autoload variable
->z=SRANDOM (zsh/random)
+1:Global -h variable doesn't hide autoload variable
>z=SRANDOM (zsh/random)
->v=integer
+?(eval):typeset:3: SRANDOM: can't change parameter attribute
zmodload -u zsh/random
echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index 5082d1011..0e1cc9e4e 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -2359,4 +2359,8 @@ F:converting from association/array to string should work here too
>typeset -n ref1=var
>typeset -n ref2
+ typeset -hn ref_h
+ typeset -Hn ref_H
+0:unsusual but legal option combinations
+
%clean