Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Remove bogus PM_LOCAL from call to resolve_nameref in createparam
- X-seq: zsh-workers 53797
- From: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: PATCH: Remove bogus PM_LOCAL from call to resolve_nameref in createparam
- Date: Sat, 21 Jun 2025 11:56:16 +0200
- Archived-at: <https://zsh.org/workers/53797>
- List-id: <zsh-workers.zsh.org>
A bogus PM_LOCAL flag in the call to resolve_nameref in createparam prevents the creation of the right variable when reference chains to not-yet-defined variables including hidden references are involved.
Example |
typeset -n ref1=var1 () { typeset -n ref2=ref1 typeset -n ref1=var2 typeset -i ref2=42 typeset -p ref1 ref2 var1 var2 } |
Current output | Expected output |
3: builtin.c:2617: BUG: parameter recreated with wrong flags typeset -n ref1=var2 typeset -n ref2=ref1 typeset -g var1=42 | (anon):typeset:4: no such variable: var2 typeset -n ref1=var2 typeset -n ref2=ref1 typeset -i var1=42 |
The following patch fixes the issue:
Philippe
diff --git a/Src/params.c b/Src/params.c
index 7b515515e..b811e4e05 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -1041,7 +1041,7 @@ createparam(char *name, int flags)
(oldpm = upscope(oldpm, oldpm->base))) {
Param lastpm;
struct asgment stop;
- stop.flags = PM_NAMEREF | (flags & PM_LOCAL);
+ stop.flags = PM_NAMEREF;
stop.name = oldpm->node.nam;
stop.value.scalar = GETREFNAME(oldpm);
lastpm = (Param)resolve_nameref(oldpm, &stop);
diff --git a/Test/K01nameref.ztst b/Test/K01nameref.ztst
index 54f0aaf68..504eb8a18 100644
--- a/Test/K01nameref.ztst
+++ b/Test/K01nameref.ztst
@@ -1179,4 +1179,18 @@ F:previously this could create an infinite recursion and crash
>typeset PS1=zz
*?*
+ unset var1 var2
+ typeset -n ref1=var1
+ () {
+ typeset -n ref2=ref1
+ typeset -n ref1=var2
+ typeset -i ref2=42
+ typeset -p ref1 ref2 var1 var2
+ }
+1:typeset reference chain to not-yet-defined variable including a hidden reference
+?(anon):typeset:4: no such variable: var2
+>typeset -n ref1=var2
+>typeset -n ref2=ref1
+>typeset -i var1=42
+
%clean
Messages sorted by:
Reverse Date,
Date,
Thread,
Author