Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vim9script] imported autoloaded functions might not exist #14775

Open
odormond opened this issue May 15, 2024 · 0 comments · May be fixed by #14885
Open

[vim9script] imported autoloaded functions might not exist #14775

odormond opened this issue May 15, 2024 · 0 comments · May be fixed by #14885
Labels

Comments

@odormond
Copy link

Steps to reproduce

  1. Put this in ~/.vim/autoload/foo.vim:
    vim9script
    
    echo "autoloading foo.vim"
    
    export def Foo()
        echo "Foo"
    enddef
    
    and put that in ~/.vim/plugin/foo.vim:
    vim9script
    
    import autoload 'foo.vim'
    
    def Setup()
        foo.Foo()
    enddef
    
    nnoremap <leader>S <ScriptCmd>Setup()<CR>
    nnoremap <leader>F <ScriptCmd>foo.Foo()<CR>
    
  2. Start vim
  3. Type <leader>S. This produces the errors:
    Error detected while compiling function <SNR>17_Setup:
    line    1:
    E1048: Item not found in script: Foo
    
  4. Type <leader>F. This echos:
    autoloading foo.vim
    Foo
    
  5. Quit and restart vim
  6. Type <leader>F. This echos:
    autoloading foo.vim
    Foo
    
  7. Type <leader>S. This works this time and echos:
    Foo
    

Notes:

  • Appending defcompile to the end of plugin/foo.vim produces the error on startup and then <leader>S consistently fails even if typed after <leader>F (which still works).
  • Replacing the call foo.Foo() in Setup() with foo#Foo() works and the autoloading foo.vim is echoed only when <leader>S is typed for the first time (if done before <leader>F of course) but in that case the import is not needed (except for the <leader>F mapping).

Expected behaviour

No error should be printed and Foo should be echoed independently of the order of invocation of the mappings.

Or the documentation should be updated to clarify how autoloaded imports should be used.

Version of Vim

9.1.412

Environment

OS: Ubuntu 22.04
terminal: tmux 3.5 in GNOME Terminal 3.44.0
$TERM: tmux-256color
shell: bash 5.1.16(1)-release

VIM - Vi IMproved 9.1 (2024 Jan 02, compiled May 15 2024 09:40:09)
Included patches: 1-412
Compiled by odormond@LAP-CH-607-LIN
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term -gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          -ruby              +wildignore
+cursorbind        -lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      -sodium            -X11
+digraphs          +mouse             -sound             +xattr
-dnd               -mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        -mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static    
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
 3rd user vimrc file: "~/.config/vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/home/odormond/.local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -fno-strength-reduce -Wall -Wno-deprecated-declarations -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lm -ltinfo -lelf 

Logs and stack traces

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant