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

Re: inconsistency of invalid identifier error messages



On Wed, 12 Nov 2008 14:50:22 +0100
Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> The following seems somewhat inconsistent. Compare the error messages
> and note the difference in whether the error is printed before or after
> the edits.
> 
> vared -c a-b
> vared -c ''
> vared -- -a
> vared -- -
> read a-b
> unset a-b
> unset 'a[b'
> 
> I think unset should be producing an error in both cases.  It's fair
> that it quitely succeeds if you unset an already unset parameter but an
> invalid parameter name is different.

Presumably this is connect to parsing subscripts?  unset 'a[b]' is not an
error if a is an associative array (even if the element b doesn't exist),
though 'a[b' obviously is.

> Any preference on what error message to standardise on. We currently
> have:
> invalid parameter name: a-b

I think this one is probably clearest.  ("Parameter" isn't a very good word
for a variable, but that's too widespread to do anything about.)

> Also, any views on whether errors should be printed before or after or
> whether it is correct that read consumes the input regardless while vared
> immediately prints the error message? Bash and Ksh have the opposite
> behaviour in this regard.

I would think having the error as soon as possible is good.

> The patch below makes the first two (vared) cases consistent with the
> third one. Any thoughts on how to best fix the last vared case (editing
> $-) and what to do about unset?

Hmmm... "-" *is* an identifier if $- is a parameter.  Maybe the test
needs fixing.  However, the parameter is readonly, and readonly specials
can't be made writeable, so a simple local fix would be to test if the
parameter existed despite the failure of the identifier test and report an
error if it was readonly.  Same with "?".

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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