[vim/vim] [vim9script] imports sourced in wrong order (Issue #15137)

4 views
Skip to first unread message

errael

unread,
Jul 2, 2024, 12:45:27 PM (12 hours ago) Jul 2
to vim/vim, Subscribed

Steps to reproduce

In f1.vim notice the statement f3.F3(f2.F2()). f2.F2() is executed before
f3.F3(); the disassembly below shows that. However, also notice in the
disassembly that SOURCE ... f3.vim comes before SOURCE ... f3.vim; the
statements are in the wrong order. This is mentioned in

#15132 (comment)

as a side issue.

The reason this is a problem, is that the loading of the file f2.vim, and
possibly the execution of f2.F2(), initializes some things required during the
loading of f3.vim.

f1.vim

vim9script

import autoload './autoload/f2.vim'
import autoload './autoload/f3.vim'

def F1()
    f3.F3(f2.F2())
enddef
disas F1

./autoload/f2.vim

vim9script

export def F2(): list<string>
    return []
enddef

./autoload/f3.vim

vim9script

export def F3(arg: list<string>)
enddef
<SNR>45_F1
    f3.F3(f2.F2())
   0 SOURCE /home/err/work/bugs/vim/import-autoload/stuff/autoload/f3.vim
   1 PUSHFUNC "f3#F3"
   2 SOURCE /home/err/work/bugs/vim/import-autoload/stuff/autoload/f2.vim
   3 PUSHFUNC "f2#F2"
   4 PCALL top (argc 0)
   5 PCALL end
   6 PCALL top (argc 1)
   7 PCALL end
   8 DROP
   9 RETURN void

Expected behaviour

This might be addressed as a documentation issue. The docs say

					*vim9-autoload* *import-autoload*
For optimal startup speed, loading scripts should be postponed until they are
actually needed.  Using the autoload mechanism is recommended:

Which makes the current behavior a bug.

Here's a simple workaround

def F1()
    #f3.F3(f2.F2())
    var x = f2.F2()
    f3.F3(x)
enddef

Version of Vim

9.1.516

Environment

ubuntu/gtk3

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/15137@github.com>

Reply all
Reply to author
Forward
0 new messages