53796: fix local reference chains and detect self-reference across local scopes

This commit is contained in:
Philippe Altherr
2025-10-26 17:05:44 -07:00
committed by Bart Schaefer
parent e1fed5439c
commit 78b7629361
3 changed files with 13 additions and 2 deletions

View File

@@ -11,6 +11,9 @@
omit base level for up-scope references; do not follow reference
chains when computing base level of new references
* Philippe: 53796: Src/params.c, Test/K01nameref.ztst: fix local
reference chains and detect self-reference across local scopes
2025-10-24 Oliver Kiddle <opk@zsh.org>
* 54002: Src/parse.c: silence compiler warning for static function

View File

@@ -6412,8 +6412,6 @@ setscope(Param pm)
stop.name = pm->node.nam;
stop.value.scalar = NULL;
stop.flags = PM_NAMEREF;
if (locallevel && !(pm->node.flags & PM_UPPER))
stop.flags |= PM_LOCAL;
dont_queue_signals(); /* Prevent unkillable loops */
basepm = (Param)resolve_nameref(pm, &stop);
restore_queue_signals(q);

View File

@@ -1179,6 +1179,16 @@ F:previously this could create an infinite recursion and crash
>typeset PS1=zz
*?*
typeset -n ref1
typeset -n ref2=ref1
() {
typeset -n ref3=ref2
typeset ref2=foo
ref1=ref3
}
1:self reference chain including a hidden reference
?(anon):3: ref3: invalid self reference
zmodload -u zsh/random
echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}
typeset -n ref=SRANDOM