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

Re: PATCH: "unset -n" removes nameref-ness



The flags are assigned at the end of createparam(), overwriting
whatever the old flags were.  PM_NAMEREF is checked too early for
that, to cause the assignment to go through to the referent instead.
So that has to be cleared before we reach createparam().

Isn't the problem that the special code path for references should only trigger if the reference is still alive? Wouldn't then the already existing clearing take place?

The proposed patch looks fragile to me because it seems that other code paths may unset references but these lack the clearing and thus the -n may get revivided. A fix that doesn't require any clearing at unset time would be much more robust.

Philippe


On Wed, Jun 11, 2025 at 7:00 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Tue, Jun 10, 2025 at 8:38 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> } else /* should this be in unsetparam_pm()? */
>
> I was expecting to find code that clears flags like PM_INTEGER in either bin_unset or in unsetparam_pm but I don't see anything like that. So it's a bit of a mystery to me how and where these flags get cleared and why only PM_NAMEREF needs to be explicitly cleared in bin_unset (or unsetparam_pm).

The flags are assigned at the end of createparam(), overwriting
whatever the old flags were.  PM_NAMEREF is checked too early for
that, to cause the assignment to go through to the referent instead.
So that has to be cleared before we reach createparam().

For top-level parameters, this doesn't apply, because unsetparam_pm()
discards them entirely from the parameter table, but it can't do that
for locallevel > 0.

> For code with no errors, clearing PM_NAMEREF in bin_unset seems good enough but there are all these places that check for errors and then sometimes unset a parameter

That's likely to be a tricky one.  An implicit reversal of an
assignment rather than an explicit unset -n might not always be
expected to undo the declaration.



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