Skip to content

Commit 938b3c9

Browse files
paltherrbartschaefer
authored andcommitted
53790: corrections to reference loop detection
1 parent 7546c18 commit 938b3c9

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* Philippe: 53797: Src/params.c, Test/K01nameref.ztst: fix creation
1818
of undeclared target variable through reference chain
1919

20+
* Philippe: 53790: Src/builtin.c, Test/K01nameref.ztst,
21+
Test/V10private.ztst: corrections to reference loop detection
22+
2023
2025-10-24 Oliver Kiddle <[email protected]>
2124

2225
* 54002: Src/parse.c: silence compiler warning for static function

Src/builtin.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,16 +3129,12 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
31293129

31303130
if (on & PM_NAMEREF) {
31313131
if (asg->value.scalar &&
3132-
((pm = (Param)resolve_nameref((Param)hn, asg)) &&
3132+
((pm = (Param)paramtab->getnode(paramtab, asg->value.scalar)) &&
31333133
(pm->node.flags & PM_NAMEREF))) {
31343134
if (pm->node.flags & PM_SPECIAL) {
31353135
zwarnnam(name, "%s: invalid reference", pm->node.nam);
31363136
returnval = 1;
31373137
continue;
3138-
} else if (pm->u.str && strcmp(pm->u.str, asg->name) == 0) {
3139-
zwarnnam(name, "%s: invalid self reference", asg->name);
3140-
returnval = 1;
3141-
continue;
31423138
}
31433139
}
31443140
if (hn) {

Test/K01nameref.ztst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,25 @@ F:unexpected side-effects of previous tests
450450
1:looping assignment not allowed
451451
*?*invalid self reference
452452

453+
typeset ptr1=not-a-ref
454+
() {
455+
typeset -n ptr1=ptr1
456+
() {
457+
typeset -n ptr1=ptr1
458+
echo $ptr1
459+
}
460+
}
461+
0:regression: not a self reference (test 1)
462+
>not-a-ref
463+
464+
typeset -n ptr1
465+
typeset -n ptr2=ptr1
466+
() {
467+
typeset ptr2=no-a-ref
468+
typeset -n ptr1=ptr2
469+
}
470+
0:regression: not a self reference (test 2)
471+
453472
unset -n ptr2
454473
typeset -n ptr2='path[2]'
455474
print -r -- $ptr2

Test/V10private.ztst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,7 @@ F:Here ptr1 points to global ptr2 so assignment succeeds
429429
setopt localoptions errreturn
430430
private -n ptr2
431431
typeset -n ptr1=ptr2
432-
typeset -p ptr1 ptr2
433-
typeset val=LOCAL
434-
() {
435-
ptr1=val
436-
typeset -n
437-
printf "v %s=%s\n" ptr1 "$ptr1" ptr2 "$ptr2"
438-
}
439-
typeset -p ptr1 ptr2
432+
echo NOT REACHED
440433
}
441434
typeset -p ptr1 ptr2
442435
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?
445438
*?*no such variable: ptr1
446439
*?*no such variable: ptr2
447440

441+
() {
442+
typeset ptr2=foo
443+
typeset -n ptr1=ptr2
444+
() {
445+
setopt localoptions errreturn
446+
private -n ptr2
447+
typeset -n ptr1=ptr2
448+
echo NOT REACHED
449+
}
450+
}
451+
1:regression test for invalid reference detection
452+
F:Should we allow "public" namerefs to private parameters?
453+
*?*ptr2: invalid reference
454+
448455
() {
449456
private x=1
450457
unset x

0 commit comments

Comments
 (0)