patch 9.1.1154: Vim9: not able to use autoload class accross scripts
Commit:
https://github.com/vim/vim/commit/e9ae35f265f4eb71f1daba319f430ca3faeaf639
Author: Yegappan Lakshmanan <[email protected]>
Date: Thu Feb 27 19:12:00 2025 +0100
patch 9.1.1154: Vim9: not able to use autoload class accross scripts
Problem: Vim9: not able to use autoload class accross scripts
Solution: make it work, re-enable the test (Yegappan Lakshmanan)
fixes: #15031
closes: #16748
Signed-off-by: Yegappan Lakshmanan <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/evalvars.c b/src/evalvars.c
index 1b11f2847..2745ac271 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3087,6 +3087,9 @@ eval_variable(
dictitem_T *v = find_var_in_ht(ht, 0, name,
flags & EVAL_VAR_NOAUTOLOAD);
+ if (v == NULL)
+ v = find_var_autoload_prefix(name, sid, NULL, NULL);
+
if (v != NULL)
{
tv = &v->di_tv;
diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim
index aa81851b4..8376a9316 100644
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -3523,77 +3523,111 @@ def Test_use_imported_class_as_type()
source Xdir/import/a.vim
enddef
-" FIXME: The following test currently fails.
-" " Test for using an autoloaded class from another autoloaded script
-" def Test_class_from_auloaded_script()
-" mkdir('Xdir', 'R')
-" var save_rtp = &rtp
-" &rtp = getcwd()
-" exe 'set rtp^=' .. getcwd() .. '/Xdir'
-"
-" mkdir('Xdir/autoload/SomeClass/bar', 'p')
-"
-" var lines =<< trim END
-" vim9script
-"
-" export class Baz
-" static var v1: string = "v1"
-" var v2: string = "v2"
-" def GetName(): string
-" return "baz"
-" enddef
-" endclass
-" END
-" writefile(lines, 'Xdir/autoload/SomeClass/bar/baz.vim', 'D')
-"
-" lines =<< trim END
-" vim9script
-"
-" import autoload './bar/baz.vim'
-"
-" export def MyTestFoo(): string
-" assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method
"NonExisting" not found in class "Baz"')
-" assert_fails('var x = baz.Baz.foobar', 'E1337: Class variable "foobar"
not found in class "Baz"')
-"
-" const instance = baz.Baz.new()
-" return $'{instance.GetName()} {baz.Baz.v1} {instance.v2}'
-" enddef
-" END
-" writefile(lines, 'Xdir/autoload/SomeClass/foo.vim', 'D')
-"
-" lines =<< trim END
-" vim9script
-"
-" import autoload 'SomeClass/foo.vim'
-" import autoload 'SomeClass/bar/baz.vim'
-"
-" def NotInAutoload()
-" # Use non-existing class method and variable
-" assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method
"NonExisting" not found in class "Baz"')
-"
-" var caught_exception = false
-" try
-" var x = baz.Baz.foobar
-" catch /E1337: Class variable "foobar" not found in class "Baz"/
-" caught_exception = true
-" endtry
-" assert_true(caught_exception)
-"
-" const instance = baz.Baz.new()
-" assert_equal("baz v1 v2", $'{instance.GetName()} {baz.Baz.v1}
{instance.v2}')
-" enddef
-"
-" def InAutoload()
-" assert_equal("baz v1 v2", foo.MyTestFoo())
-" enddef
-"
-" NotInAutoload()
-" InAutoload()
-" END
-" v9.CheckScriptSuccess(lines)
-"
-" &rtp = save_rtp
-" enddef
+" Test for using an autoloaded class from another autoloaded script
+def Test_class_from_auloaded_script()
+ mkdir('Xdir', 'R')
+ var save_rtp = &rtp
+ &rtp = getcwd()
+ exe 'set rtp^=' .. getcwd() .. '/Xdir'
+
+ mkdir('Xdir/autoload/SomeClass/bar', 'p')
+
+ var lines =<< trim END
+ vim9script
+
+ export class Baz
+ static var v1: string = "v1"
+ var v2: string = "v2"
+ def GetName(): string
+ return "baz"
+ enddef
+ endclass
+ END
+ writefile(lines, 'Xdir/autoload/SomeClass/bar/baz.vim', 'D')
+
+ lines =<< trim END
+ vim9script
+
+ import autoload './bar/baz.vim'
+
+ export def MyTestFoo(): string
+ assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method
"NonExisting" not found in class "Baz"')
+ assert_fails('var x = baz.Baz.foobar', 'E1337: Class variable "foobar"
not found in class "Baz"')
+
+ const instance = baz.Baz.new()
+ return $'{instance.GetName()} {baz.Baz.v1} {instance.v2}'
+ enddef
+ END
+ writefile(lines, 'Xdir/autoload/SomeClass/foo.vim', 'D')
+
+ lines =<< trim END
+ vim9script
+
+ import autoload 'SomeClass/foo.vim'
+ import autoload 'SomeClass/bar/baz.vim'
+
+ def NotInAutoload()
+ # Use non-existing class method and variable
+ assert_fails('var x = baz.Baz.NonExisting()', 'E1325: Method
"NonExisting" not found in class "Baz"')
+
+ var caught_exception = false
+ try
+ var x = baz.Baz.foobar
+ catch /E1337: Class variable "foobar" not found in class "Baz"/
+ caught_exception = true
+ endtry
+ assert_true(caught_exception)
+
+ const instance = baz.Baz.new()
+ assert_equal("baz v1 v2", $'{instance.GetName()} {baz.Baz.v1}
{instance.v2}')
+ enddef
+
+ def InAutoload()
+ assert_equal("baz v1 v2", foo.MyTestFoo())
+ enddef
+
+ NotInAutoload()
+ InAutoload()
+ END
+ v9.CheckScriptSuccess(lines)
+
+ &rtp = save_rtp
+enddef
+
+" Test for using an autoloaded enum from another script
+def Test_enum_from_auloaded_script()
+ mkdir('Xdir', 'R')
+ var save_rtp = &rtp
+ &rtp = getcwd()
+ exe 'set rtp^=' .. getcwd() .. '/Xdir'
+
+ mkdir('Xdir/autoload/', 'p')
+
+ var lines =<< trim END
+ vim9script
+ export enum Color
+ Red,
+ Green,
+ Blue
+ endenum
+ END
+ writefile(lines, 'Xdir/autoload/color.vim', 'D')
+
+ lines =<< trim END
+ vim9script
+
+ import autoload 'color.vim'
+
+ def CheckColor()
+ var c = color.Color.Green
+ assert_equal('Green', c.name)
+ enddef
+ CheckColor()
+ END
+ v9.CheckScriptSuccess(lines)
+
+ &rtp = save_rtp
+enddef
" Test for using a non-exported constant as an instance variable initiazer in
an
" imported class
diff --git a/src/version.c b/src/version.c
index 2d2188a87..6e668fc6a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1154,
/**/
1153,
/**/
diff --git a/src/vim9class.c b/src/vim9class.c
index cbb91f4fe..1c54474e4 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -2063,7 +2063,7 @@ early_ret:
tv.v_type = VAR_CLASS;
tv.vval.v_class = cl;
SOURCING_LNUM = start_lnum;
- int rc = set_var_const(cl->class_name, current_sctx.sc_sid, NULL, &tv,
FALSE, 0, 0);
+ int rc = set_var_const(cl->class_name, 0, NULL, &tv, FALSE, 0, 0);
if (rc == FAIL)
goto cleanup;
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1tniPe-00GaEZ-1q%40256bit.org.