Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: Disallow array initializer for named reference
On Tue, Jun 10, 2025 at 3:38 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Jun 10, 2025 at 2:07 PM Philippe Altherr
> <philippe.altherr@xxxxxxxxx> wrote:
> >
> > I would rather change the existing "inconsistent type for assignment" errors into warnings than change the new one into an error.
>
> Yeah, that probably wouldn't fly, because scripts that now stop would
> instead continue running with parameters that don't exist or have
> different type than before.
OK, the attache handles the error at the same point in the code where
other "inconsistent type" errors are handled, so that's very
consistent. Separate patch for the options mismatching.
One curious thing (and this is true of this error for pre-existing
cases, not just namerefs):
% () {
{ typeset -n ref1 ref2=(x) ref3=foo } always
{ typeset -p ref1 ref2 ref3 }
}
(anon):typeset:1: ref2: inconsistent type for assignment
(anon):typeset:2: no such variable: ref2
typeset -n ref1=''
typeset -n ref3=foo
Note that despite the error on the second declaration, all three
declarations were completed. This happens because bin_typeset() calls
typeset_single() in a loop, and does not break the loop on errflag.
Patch replaces workers/53758.
diff --git a/Src/builtin.c b/Src/builtin.c
index 5563bdba9..91a62aa39 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2230,7 +2230,8 @@ typeset_single(char *cname, char *pname, Param pm, int func,
else if (OPT_PLUS(ops,'p') && off && !(off & pm->node.flags))
return NULL;
if ((asg->flags & ASG_ARRAY) ?
- !(PM_TYPE(pm->node.flags) & (PM_ARRAY|PM_HASHED)) :
+ (!(PM_TYPE(pm->node.flags) & (PM_ARRAY|PM_HASHED)) ||
+ (pm->node.flags & PM_NAMEREF)) :
(asg->value.scalar && (PM_TYPE(pm->node.flags &
(PM_ARRAY|PM_HASHED))))) {
zerrnam(cname, "%s: inconsistent type for assignment", pname);
@@ -2344,7 +2345,7 @@ typeset_single(char *cname, char *pname, Param pm, int func,
return NULL; /* Nothing to print */
if ((asg->flags & ASG_ARRAY) ?
- !(on & (PM_ARRAY|PM_HASHED)) :
+ (!(on & (PM_ARRAY|PM_HASHED)) || (on & PM_NAMEREF)) :
(asg->value.scalar && (on & (PM_ARRAY|PM_HASHED)))) {
zerrnam(cname, "%s: inconsistent type for assignment", pname);
return NULL;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author