summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-03-31 16:18:23 +0100
committerBram Moolenaar <Bram@vim.org>2022-03-31 16:18:23 +0100
commitccbfd4883f0385a1d84cc87785ddcc86185b4ad9 (patch)
tree65f63c71b3792956985261e7ae0e4a02df0e9884
parent1104a6d0c2004d39e9b6cb8f804d12b628a69869 (diff)
downloadvim-git-8.2.4656.tar.gz
patch 8.2.4656: Vim9: can't use item from "import autoload" with autoload dirv8.2.4656
Problem: Vim9: can't use items from "import autoload" with autoload directory name. Solution: Let sn_autoload_prefix overrule sn_import_autoload. (closes #10054)
-rw-r--r--src/structs.h1
-rw-r--r--src/testdir/test_vim9_import.vim25
-rw-r--r--src/version.c2
-rw-r--r--src/vim9expr.c54
-rw-r--r--src/vim9instr.c4
-rw-r--r--src/vim9script.c3
6 files changed, 64 insertions, 25 deletions
diff --git a/src/structs.h b/src/structs.h
index 737b9f90e..6c92f073f 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -1868,6 +1868,7 @@ typedef struct
char_u *sn_autoload_prefix;
// TRUE for a script used with "import autoload './dirname/script.vim'"
+ // For "../autoload/script.vim" sn_autoload_prefix is also set.
int sn_import_autoload;
# ifdef FEAT_PROFILE
diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim
index c6a820654..2c7e73100 100644
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -969,6 +969,31 @@ def Test_autoload_import_relative()
delete('XimportRel3.vim')
enddef
+def Test_autoload_import_relative_autoload_dir()
+ mkdir('autoload', 'p')
+ var lines =<< trim END
+ vim9script
+ export def Bar()
+ g:called_bar = 'yes'
+ enddef
+ END
+ writefile(lines, 'autoload/script.vim')
+
+ lines =<< trim END
+ vim9script
+ import autoload './autoload/script.vim'
+ def Foo()
+ script.Bar()
+ enddef
+ Foo()
+ assert_equal('yes', g:called_bar)
+ END
+ v9.CheckScriptSuccess(lines)
+
+ unlet g:called_bar
+ delete('autoload', 'rf')
+enddef
+
func Test_import_in_diffexpr()
CheckExecutable diff
diff --git a/src/version.c b/src/version.c
index dd1331ea9..ade858dc2 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4656,
+/**/
4655,
/**/
4654,
diff --git a/src/vim9expr.c b/src/vim9expr.c
index 6576fc8ea..72bf1adbd 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -298,26 +298,31 @@ compile_load_scriptvar(
*p = NUL;
si = SCRIPT_ITEM(import->imp_sid);
- if (si->sn_autoload_prefix != NULL
- && si->sn_state == SN_STATE_NOT_LOADED)
- {
- char_u *auto_name = concat_str(si->sn_autoload_prefix, exp_name);
+ if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
+ // "import autoload './dir/script.vim'" or
+ // "import autoload './autoload/script.vim'" - load script first
+ res = generate_SOURCE(cctx, import->imp_sid);
- // autoload script must be loaded later, access by the autoload
- // name. If a '(' follows it must be a function. Otherwise we
- // don't know, it can be "script.Func".
- if (cc == '(' || paren_follows_after_expr)
- res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
- else
- res = generate_AUTOLOAD(cctx, auto_name, &t_any);
- vim_free(auto_name);
- done = TRUE;
- }
- else if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
+ if (res == OK)
{
- // "import autoload './dir/script.vim'" - load script first
- res = generate_SOURCE(cctx, import->imp_sid);
- if (res == OK)
+ if (si->sn_autoload_prefix != NULL
+ && si->sn_state == SN_STATE_NOT_LOADED)
+ {
+ char_u *auto_name =
+ concat_str(si->sn_autoload_prefix, exp_name);
+
+ // autoload script must be loaded later, access by the autoload
+ // name. If a '(' follows it must be a function. Otherwise we
+ // don't know, it can be "script.Func".
+ if (cc == '(' || paren_follows_after_expr)
+ res = generate_PUSHFUNC(cctx, auto_name, &t_func_any);
+ else
+ res = generate_AUTOLOAD(cctx, auto_name, &t_any);
+ vim_free(auto_name);
+ done = TRUE;
+ }
+ else if (si->sn_import_autoload
+ && si->sn_state == SN_STATE_NOT_LOADED)
{
// If a '(' follows it must be a function. Otherwise we don't
// know, it can be "script.Func".
@@ -331,14 +336,15 @@ compile_load_scriptvar(
else
res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
import->imp_sid, &t_any);
+ done = TRUE;
+ }
+ else
+ {
+ idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
+ cctx, NULL, TRUE);
}
- done = TRUE;
- }
- else
- {
- idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
- cctx, NULL, TRUE);
}
+
*p = cc;
*end = p;
if (done)
diff --git a/src/vim9instr.c b/src/vim9instr.c
index ae828cbe7..ab52d4c4c 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -1932,7 +1932,9 @@ generate_store_var(
isntype_T isn_type = ISN_STORES;
if (SCRIPT_ID_VALID(scriptvar_sid)
- && SCRIPT_ITEM(scriptvar_sid)->sn_import_autoload)
+ && SCRIPT_ITEM(scriptvar_sid)->sn_import_autoload
+ && SCRIPT_ITEM(scriptvar_sid)->sn_autoload_prefix
+ == NULL)
{
// "import autoload './dir/script.vim'" - load script first
if (generate_SOURCE(cctx, scriptvar_sid) == FAIL)
diff --git a/src/vim9script.c b/src/vim9script.c
index a63f2f7dd..cd9ff92cd 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -415,6 +415,9 @@ handle_import_fname(char_u *fname, int is_autoload, int *sid)
si = SCRIPT_ITEM(*sid);
si->sn_import_autoload = TRUE;
+ if (si->sn_autoload_prefix == NULL)
+ si->sn_autoload_prefix = get_autoload_prefix(si);
+
// with testing override: load autoload script right away
if (!override_autoload || si->sn_state != SN_STATE_NOT_LOADED)
return OK;