Steps to reproduce
Run this shell command:
vim -Nu NONE -S <(tee <<'EOF'
vim9script
var dir = '/tmp/.vim/autoload'
dir->mkdir('p')
var lines =<< trim END
vim9script autoload
export def Item(arg: string)
echomsg arg
enddef
END
lines->writefile(dir .. '/script.vim')
set rtp^=/tmp/.vim
import autoload 'script.vim'
def Func()
'base'->script.Item()
enddef
Func()
EOF
)
E121 is given:
E121: Undefined variable: g:script#Item
Expected behavior
No error is given. base is echo'ed.
Version of Vim
8.2 Included patches: 1-4128
Environment
Operating system: Ubuntu 20.04.3 LTS
Terminal: xterm
Value of $TERM: xterm-256color
Shell: zsh 5.8
Additional context
No issue if the method call is used at the script level:
vim9script var dir = '/tmp/.vim/autoload' dir->mkdir('p') var lines =<< trim END vim9script autoload export def Item(arg: string) echomsg arg enddef END lines->writefile(dir .. '/script.vim') set rtp^=/tmp/.vim import autoload 'script.vim' 'base'->script.Item()
base
No issue when using a regular import/ script (i.e. not autoloaded):
vim9script var dir = '/tmp/.vim/import' dir->mkdir('p') var lines =<< trim END vim9script export def Item(arg: string) echomsg arg enddef END lines->writefile(dir .. '/script.vim') set rtp^=/tmp/.vim import 'script.vim' def Func() 'base'->script.Item() enddef Func()
base
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Also, if we try to import an autoloaded script, and Vim fails to find it, a confusing error is given:
vim9script var dir = '/tmp/.vim/autoload' dir->mkdir('p'
) ['vim9script autoload']->writefile(dir .. '/script.vim') import autoload 'script.vim'
E1264: Autoload import cannot use absolute or relative path: script.vim
It's confusing because we can use a relative path:
vim9script var dir = '/tmp/.vim/autoload' dir->mkdir('p'
) ['vim9script autoload']->writefile(dir .. '/script.vim') &runtimepath = '/tmp/.vim' import autoload 'script.vim'
no error
There is an ambiguity: script.vim can be seen as a filename, or as a path relative to /tmp/.vim/autoload/.
Anyway, the issue is not that we have used a path (relative or absolute); the issue is simply that we haven't properly updated the runtimepath so that Vim can find the autoload directory containing the script.
A better error message would be:
E1234: cannot find autoload script "script.vim" in runtimepath
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
It's confusing because we can use a relative path:
Actually, what's really confusing is that Vim refers to script.vim as a path, while for the user it seems to be a simple file name.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
Actually, what's really confusing is that Vim refers to script.vim as a path, while for the user it seems to be a simple file name.
I think the error message should be different depending on whether the argument passed to import autoload contains a path separator (slash on Unix-like systems, backslash on Windows?).
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
This happens because "script.Item" is compiled without knowing whether
it is a function reference or something else.
I forgot: the issue only affected a method call:
# ERROR
'base'->script.Item()
# OK
script.Item('base')
I would have thought that if Vim was able to infer that script.Item was a function reference in the second case, it would come to the same conclusion in the first one.
We'll have to deal with this at runtime.
The error was already given at runtime. I hope it doesn't mean that we lose some type checking at compile time when we use a method call. Otherwise, I might be tempted to avoid methods when calling a function from an import autoload script.
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.![]()