vim / vim

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

E117 (Unknown function) error when using call w/ vim9script #9510

Closed dvogel closed 2 years ago

dvogel commented 2 years ago

Steps to reproduce

In demo9.vim:

vim9script
export def MyFunc(): void
    return
enddef

In main.vim:

vim9script
import "./demo9.vim" as demo9
call demo9.MyFunc()

Run vim --clean -u main.vim, get error on line 3.

Expected behaviour

I would expect the function to be found and called. From :h call:

                In |Vim9| script using `:call` is optional, these two lines do
                the same thing:  
                        call SomeFunc(arg)
                        SomeFunc(arg)

Removing call from line 3 does cause the function to be found and called as expected.

Version of Vim

v8.2.4063

Environment

Debian, bash, xterm-256color

Logs and stack traces

Error detected while processing /home/dvogel/tmp/vim9demo/main.vim:
line    3:
E117: Unknown function: MyFunc
bfrg commented 2 years ago

If you call the function through a reference it works:

vim9script
import "./demo9.vim"
const MyFunc = demo9.MyFunc
call MyFunc()

Surprisingly, when the reference is added call demo9.MyFunc() works, too:

vim9script
import "./demo9.vim"
const MyFunc = demo9.MyFunc
call demo9.MyFunc()
brammool commented 2 years ago

If you call the function through a reference it works:

vim9script
import "./demo9.vim"
const MyFunc = demo9.MyFunc
call MyFunc()

Surprisingly, when the reference is added call demo9.MyFunc() works, too:

vim9script
import "./demo9.vim"
const MyFunc = demo9.MyFunc
call demo9.MyFunc()

That was a mistake, it ignored the "demo9." part. If the local variable is given another name it fails again.

The last couple of patches should have fixed this.

The change in the import syntax was relying on the already implemented "* as Name" functionality, but it turns out that wasn't completely finished.

-- ZOOT: I'm afraid our life must seem very dull and quiet compared to yours. We are but eightscore young blondes, all between sixteen and nineteen-and-a-half, cut off in this castle, with no one to protect us. Oooh. It is a lonely life ... bathing ... dressing ... undressing ... making exciting underwear.... "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// 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 ///