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

Re: [Language Design] How should references to localized special parameters behave?



On Fri, Aug 14, 2026 at 3:37 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> What if builtin.c typeset_single() marked the pseudo parameter as
>> read-only and params.c scanendscope() undid that when restoring?  (Or
>> an equivalent.)
>
> That wouldn't be enough because even just expanding $home triggers the segmentation fault. For standalone special parameters, turning the hidden instance into a functional one (but with no specialness) isn't difficult.

That approach seems superficially OK, but it's somewhat orthogonal to
whether the (in that case functional) instance is read-only.  What
happens if the hidden nonspecial instance is modified?  When
special-ness is restored on scope exit, are the changes discarded or
do they take effect as if an assignment occurred at the moment of
scope change?  If the hidden nonspecial is read-only, it can't be
modified, so this question goes away.

> This approach is only problematic with tied special parameters. However, in my work on inline assignments (workers/55075), I found that most difficulties go away if one assumes that localizing one of the two tied parameters also localizes the other one

My concern with this is that it "silently" creates a second local,
which then can't be altered by a new "local".  As a contrived example,
what if the function is intended to create $HOME as (preserving of)
special but $home as (a hiding) nonspecial?

What happens if you prefix a function call with an assignment to one
part of a tied parameter and then use "local" on the other part inside
the function?

> Then, when a pair of tied parameters is localized, the hidden pair can remain tied and functional (but with no specialness).

For non-special tied parameters, unsetting either of them unties them.
This is not true of tied specials.  What happens if one of the hidden
nonspecial former-specials is unset?

Aside: workers/55021 does not prevent segfault here:
% typeset -n foo=path
% () { local path; unset foo }
zsh: segmentation fault  Src/zsh -f




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