Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Disallow array initializer for named reference



Regarding the message, I would definitively adopt the "inconsistent type for assignment" one, which I find much more understandable in this context. The message "-a not allowed with -n" looks odd since there is no -a in the statement that triggers it.

Whether that should be an error or a warning, I don't have any strong opinion. I don't have a good grasp of why some places emit errors while others emit warnings. Often it looks rather random to me. In this case, a warning looks good enough to me. And if we absolutely wanted to be consistent, I would rather change the existing "inconsistent type for assignment" errors into warnings than change the new one into an error.

Philippe


On Tue, Jun 10, 2025 at 10:17 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Tue, Jun 10, 2025 at 7:34 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> With that patch, I get this:
>
> $ typeset -n ref=(var1 var2)
> typeset: -a not allowed with -n
>
> which is a bit confusing as there is no -a.

Debated about this, landed on producing the same output for the same
flavor of discrepancy, but not married to it.

> If I replace your zwarnnam with the zerrnam used for -i
> then I get a similar error message which looks more appropriate:
>
> $ typeset -n ref=(var1 var2)
> typeset: ref: inconsistent type for assignment

So, another conundrum.  zerrnam actually sets errflag and kills the
entire context at that point.  The "-a not allowed with -n" warning
just returns $? = 1 from typeset without setting errflag.  So the
question is whether both or neither should set errflag ... I went with
neither, because after an earlier discussion it was concluded that
this should happen:

% typeset -ailn foo
typeset: -a not allowed with -n
typeset: -i not allowed with -n
typeset: -l not allowed with -n

I'm not wedded to that either, but as it stands the comparison with -i
is not entirely apt, because for most bad flag combinations we
silently discard the nonsensical ones:

% typeset -ai thing
% typeset -p thing
typeset -i thing=0


Messages sorted by: Reverse Date, Date, Thread, Author