53790: corrections to reference loop detection

This commit is contained in:
Philippe Altherr 2025-10-26 17:21:15 -07:00 committed by Bart Schaefer
parent 7546c18076
commit 938b3c9475
4 changed files with 38 additions and 13 deletions

View File

@ -17,6 +17,9 @@
* Philippe: 53797: Src/params.c, Test/K01nameref.ztst: fix creation
of undeclared target variable through reference chain
* Philippe: 53790: Src/builtin.c, Test/K01nameref.ztst,
Test/V10private.ztst: corrections to reference loop detection
2025-10-24 Oliver Kiddle <opk@zsh.org>
* 54002: Src/parse.c: silence compiler warning for static function

View File

@ -3129,16 +3129,12 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
if (on & PM_NAMEREF) {
if (asg->value.scalar &&
((pm = (Param)resolve_nameref((Param)hn, asg)) &&
((pm = (Param)paramtab->getnode(paramtab, asg->value.scalar)) &&
(pm->node.flags & PM_NAMEREF))) {
if (pm->node.flags & PM_SPECIAL) {
zwarnnam(name, "%s: invalid reference", pm->node.nam);
returnval = 1;
continue;
} else if (pm->u.str && strcmp(pm->u.str, asg->name) == 0) {
zwarnnam(name, "%s: invalid self reference", asg->name);
returnval = 1;
continue;
}
}
if (hn) {

View File

@ -450,6 +450,25 @@ F:unexpected side-effects of previous tests
1:looping assignment not allowed
*?*invalid self reference
typeset ptr1=not-a-ref
() {
typeset -n ptr1=ptr1
() {
typeset -n ptr1=ptr1
echo $ptr1
}
}
0:regression: not a self reference (test 1)
>not-a-ref
typeset -n ptr1
typeset -n ptr2=ptr1
() {
typeset ptr2=no-a-ref
typeset -n ptr1=ptr2
}
0:regression: not a self reference (test 2)
unset -n ptr2
typeset -n ptr2='path[2]'
print -r -- $ptr2

View File

@ -429,14 +429,7 @@ F:Here ptr1 points to global ptr2 so assignment succeeds
setopt localoptions errreturn
private -n ptr2
typeset -n ptr1=ptr2
typeset -p ptr1 ptr2
typeset val=LOCAL
() {
ptr1=val
typeset -n
printf "v %s=%s\n" ptr1 "$ptr1" ptr2 "$ptr2"
}
typeset -p ptr1 ptr2
echo NOT REACHED
}
typeset -p ptr1 ptr2
1:up-reference for private namerefs, end is in scope but private
@ -445,6 +438,20 @@ F:Should we allow "public" namerefs to private parameters?
*?*no such variable: ptr1
*?*no such variable: ptr2
() {
typeset ptr2=foo
typeset -n ptr1=ptr2
() {
setopt localoptions errreturn
private -n ptr2
typeset -n ptr1=ptr2
echo NOT REACHED
}
}
1:regression test for invalid reference detection
F:Should we allow "public" namerefs to private parameters?
*?*ptr2: invalid reference
() {
private x=1
unset x