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

Re: PATCH: Fix loading of autoload variable accessed via a reference



Note that the second to last test in Test/B02typeset.ztst (Local non -h variable hides autoload variable) exhibits what I think is a bug: the non -h variable should NOT hide the autoload variable. This is already so today. It's unaffected by this change. I haven't (yet) looked into why this is happening but in any case it's orthogonal to what this patch fixes.

Philippe


On Fri, Jun 13, 2025 at 2:14 PM Philippe Altherr <philippe.altherr@xxxxxxxxx> wrote:
When a reference to an autoload variable is defined, the autoload variable should be loaded. The autoload variable should also be loaded whenever such a reference is dereferenced. The latter is currently failing if the reference includes a subscript. The latter is also failing and produces bogus results when the autoload variable is hidden by a local variable. In this case it fails both with and without subscript.

The patch fixes these issues. It introduces a new loadparamnode function, which is a more sensible alternative to the getparamnode_nofollow function introduced in the original patches for setscope (workers/53688).

Below are 3 examples that exhibit the issues:

Example

zmodload -u zsh/random

echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}

typeset -n ref=SRANDOM[1,20]

echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}

echo v=${ref/<->/integer}

zmodload -u zsh/random

echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}

echo v=${ref/<->/integer}


Current output

Expected output

z=SRANDOM (zsh/random)

z=

v=integer

z=SRANDOM (zsh/random)

v=zsh/random

z=SRANDOM (zsh/random)

z=

v=integer

z=SRANDOM (zsh/random)

v=integer


Example

() {

  typeset -n ref=SRANDOM

  echo v=${ref/<->/integer}

  zmodload -u zsh/random

  echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}

  typeset -h SRANDOM=local-variable

  echo v=${ref/<->/integer}

  echo NOT REACHED

}


Current output

Expected output

v=integer

z=SRANDOM (zsh/random)

v=local-variable

NOT REACHED

v=integer

z=SRANDOM (zsh/random)

<error-message>


Example

() {

  typeset -n ref=SRANDOM[1,20]

  echo v=${ref/<->/integer}

  zmodload -u zsh/random

  echo z=${(M)${(f)${ zmodload -ap}}:#*SRANDOM*}

  typeset -h SRANDOM=local-variable

  echo v=${ref/<->/integer}

  echo NOT REACHED

}


Current output

Expected output

v=integer

z=SRANDOM (zsh/random)

v=zsh/random

NOT REACHED

v=integer

z=SRANDOM (zsh/random)

<error-message>


Philippe




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