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

Re: crash with nameref and local argv



On Wed, Nov 5, 2025 at 9:26 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Nov 4, 2025 at 9:23 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> >
> > Would that break this code (which currently works)?
> > % () { local -h argv=hello; () { local argv=( $argv ); typeset -nu
> > foo=argv; echo $foo } } noot
> > hello
>
> Yes, it would ... but the test for whether "typeset -nu foo=argv" is
> valid becomes really ugly in that case, because it's no longer just
> syntactic ... it's necessary to instead find out if there actually
> exists a local variable "argv" (or "ARGC") at exactly one level less
> than the current scope.
>
> The semantics of something like the following is therefore pretty murky:
>
> () {
>   local -h argv=hello;
>   () {
>     : There is an argv in this scope that is not the outer local
>     () {
>       typset -nu foo=argv # What does this mean?
>     }
>   }
> }
>
> Seems like a blanket ban on referencing $argv makes more sense, given
> that $@ and $* are also "illegal", even if it breaks your current
> example; I don't think it's possible to make the general case of
> peeking up the C stack succeed, so the alternative is to have it fail
> unpredictably at dereference time.

That makes sense, just wanted to make sure all bases were considered.

-- 
Mikael Magnusson




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