vim9script
export class My_class
this.hello: string
endclass
export def Return_my_class(): My_class
var r = My_class.new('From my_test_autoloaded_script')
return r
enddef
vim9script
import autoload 'autoloaded_script.vim'
def My_func()
var whatever = autoloaded_script.Return_my_class()
echo whatever.hello
enddef
My_func()
You'll see E715: Dictionary required. This doesn't happen if you move the code outside the function; it doesn't happen if you declare the class inside the script you're sourcing. It doesn't happen when you call the class's constructure inside your test file.
I'm guessing that this issue stems from the same space as that those mentioned in #11822 and #12024.
You'd expect it to print "From my_test_autoloaded_script".
9.0.1427
Fedora 37
Kitty
xterm-kitty
Zsh
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
These issues, along with #12196, may originate from the same reason: Vim rely on the typing information it knows at the point when the code is compiled to generate proper instructions, and for member access with any/unknown type as its lhs, Vim would generate STRINGMEMBER instruction to index the member by its name; the problem is that the instruction only accept dictionaries as lhs, thus the error is raised.
So as a workaround now, give a more precise explicit typing can solve this: it forces Vim to generate proper instructions to access the correct member. This is an example:
a.vim:
vim9script export class T this.n: string def F() echom "F:" this.n enddef endclass export def RT(): T return T.new("QWQ") enddef
b.vim:
vim9script import autoload "./a.vim" def F() var v: a.T = a.RT() echo v.n v.F() enddef F()
a: a.T forces Vim to generate the correct instruction.
BTW, since the use of any is inevitable now, I think maybe the only solution is to extend STRINGMEMBER instruction, allowing it to access class members and functions.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Thank for this workaround; adding the typing hadn't occurred to me.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Just an FYI, this has nothing to do with autoload. Putting the two files in the same directory, with a primary file that looks like the following also fails.
vim9script
import './f2.vim'
def My_func()
echo f2.Return_my_class().hello
enddef
My_func()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #12198 as completed via 56d45f1.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()