1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-06-20 22:18:02 +02:00

52115: permit repeated "private" declarations as long as types aren't changed

This commit is contained in:
Bart Schaefer 2023-09-05 18:04:09 -07:00
parent c0caef5613
commit e3c2af216b
3 changed files with 68 additions and 3 deletions

View file

@ -1,3 +1,8 @@
2023-09-05 Bart Schaefer <schaefer@zsh.org>
* 52115: Src/Modules/param_private.c, Test/V10private.ztst: permit
repeated "private" declarations as long as types aren't changed
2023-09-04 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
* 52112: Completion/BSD/Command/_jexec,

View file

@ -87,9 +87,52 @@ makeprivate(HashNode hn, UNUSED(int flags))
((pm->node.flags & (PM_SPECIAL|PM_REMOVABLE)) == PM_SPECIAL &&
/* typeset_single() line 2300 discards PM_REMOVABLE -- why? */
!is_private(pm->old))))) {
zwarnnam("private", "can't change scope of existing param: %s",
if (is_private(pm->old)) {
if (pm->old->node.flags & PM_READONLY) {
zerr("read-only variable: %s", pm->node.nam);
makeprivate_error = 1;
} else if ((pm->node.flags | pm->old->node.flags) ==
pm->old->node.flags) {
/* private called twice on same parameter */
Param tpm = pm;
pm = pm->old;
--locallevel;
/* why have a union if we need this switch anyway? */
switch (PM_TYPE(pm->node.flags)) {
case PM_SCALAR:
pm->gsu.s->setfn(pm, tpm->u.str);
tpm->u.str = NULL;
break;
case PM_INTEGER:
pm->gsu.i->setfn(pm, tpm->u.val);
break;
case PM_EFLOAT:
case PM_FFLOAT:
pm->gsu.f->setfn(pm, tpm->u.dval);
break;
case PM_ARRAY:
pm->gsu.a->setfn(pm, tpm->u.arr);
tpm->u.arr = NULL;
break;
case PM_HASHED:
pm->gsu.h->setfn(pm, tpm->u.hash);
tpm->u.hash = NULL;
break;
}
++locallevel;
if (!(tpm->node.flags & PM_UNSET))
pm->node.flags &= ~PM_UNSET;
} else {
zerrnam("private",
"can't change type of private param: %s",
pm->node.nam);
makeprivate_error = 1;
}
} else {
zerrnam("private", "can't change scope of existing param: %s",
pm->node.nam);
makeprivate_error = 1;
}
return;
}
struct gsu_closure *gsu = zalloc(sizeof(struct gsu_closure));

View file

@ -384,6 +384,23 @@ F:Should we allow "public" namerefs to private parameters?
}
0:regression test for unset private
() {
private x=1
unset x
private x=2
print $x
}
0:private may be called twice
>2
() {
private x=1
private -a x
print $x
}
1:private may not change parameter type
?(anon):private:2: can't change type of private param: x
%clean
rm -r private.TMP