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

Re: Should defining a reference to an autoload parameter load it?



On Tue, Jun 10, 2025 at 11:24 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> Here is an example that will behave differently depending on whether loading happens or not at definition time:
>
> () {
>   typeset -n ref=SRANDOM[1,20];
>   typeset SRANDOM=local-variable
>   echo $ref
> }

This is one of the things that the upscope() your patches removed from
createparam() was checking for:  a special hidden by a local.  (Might
nevertheless have had some of the edge cases wrong.)  If loading
happens (or if the named reference declaration is omitted), you should
see this:

(anon):2: read-only variable: SRANDOM

because the default for locals with the same name as specials is to
retain the special behavior.  This is currently broken with your
patches applied, including the explicit case:

   local +h SRANDOM

This is avoided by

  local -h SRANDOM

in which event your analysis about named reference dereferencing does apply.




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