vim / vim

The official Vim repository
https://www.vim.org
Vim License
36.64k stars 5.46k forks source link

Vim9: unknown error when calling autoload function imported from script with invalid relative path #10049

Closed lacygoill closed 2 years ago

lacygoill commented 2 years ago

Steps to reproduce

Run this shell command:

vim -Nu NONE -S <(tee <<'EOF'
    vim9script
    import autoload '...../script.vim'
    def Foo()
        script.Bar()
    enddef
    Foo()
EOF
)

An error is given. This is expected, because of the specified file path in the import autoload command, which is invalid:

import autoload '...../script.vim'
                 ^---^
                 does not mean anything

The given error message is:

E1099: Unknown error while executing <SNR>1_Foo

This is not expected.

Expected behavior

The given error message is more specific than the current catch-all "unknown error".

Version of Vim

8.2 Included patches: 1-4651

Environment

Operating system: Ubuntu 20.04.4 LTS Terminal: xterm Value of $TERM: xterm-256color Shell: GNU bash, version 5.0.17

lacygoill commented 2 years ago

Actually, an error should be given earlier, as soon as import autoload is sourced.


There might be other issues with the new syntax allowing relative paths, but I'll wait for this issue to be fixed before trying to do more tests.

brammool commented 2 years ago

Actually, an error should be given earlier, as soon as import autoload is sourced.

We can check if the file exists. At this point the name is turned into the full path, so that when the same script is used with different "import" arguments we still see it as the same script. Thus we should also be able to check if it exists with just one system call.

There might be other issues with the new syntax allowing relative paths, but I'll wait for this issue to be fixed before trying to do more tests.

Yes, please do try it out. The fix for this error should not matter though. When implementing this I found that it's more tricky, since we cannot fall back to the existing autoload mechanism that recognizes the script#item syntax.

Also, once the script did get loaded the items can be found and the behavior will be different. Thus if you compile a function before the autoload script is loaded it cannot check types, but if the script was already loaded it can give error messages at compile time.

-- Vi beats Emacs to death, and then again! http://linuxtoday.com/stories/5764.html

/// Bram Moolenaar -- @.*** -- http://www.Moolenaar.net \\ /// \\ \\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\ help me help AIDS victims -- http://ICCF-Holland.org ///