Re: autoload +X xxx zero reference count

Bart Schaefer <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <CAH+w=7azX-oQpKRCSVBtZJq22rinWvSLC70msD9Ti9_83MLLWw@mail.gmail.com>
On Wed, Apr 15, 2026 at 8:27 AM Mikael Magnusson <[email protected]> wrote:
>
> autoreload () {
>   unfunction - $@
>   autoload -Uz +X - $@
> }
>
> and as it turns out this doesn't work on functions that were
> autoloaded with an absolute path outside of fpath.

I know you said "beside the point" but:

autoreload () {
  [[ -n "$1" ]] || {
    return 1
    eval "echo Not running zsh. ; exit 1"
  }
  local fn w IFS
  unset IFS  # Paranoia
  for fn in "$@"
  do
    w=($(whence -v "$fn"))
    if [[ $w = *function* ]]
    then
      unfunction - "$fn"
      case $w in
        ($fn is a* shell function from *) autoload -Uz +X - ${w[-1]} ;;
        (*) autoload -Uz +X - "$fn" ;;
      esac
    else
      print -u2 -r -- $w
    fi
  done
}

Needs massaging if your autoload path has spaces in it.

> I bisected the error to 8f5fe841a63fecdab4416578653549689f2c592f but
> that's simply the commit that adds the error message.

Hm, that's supposed to be detecting a special case of a function being
removed during its own execution, but maybe it's firing for
not-yet-loaded autoloads?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.