summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-01-22 11:00:02 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-22 11:00:02 +0000
commit3d8e25a6d2660432df033cdad29f981ffe6ae0fc (patch)
treed19a8d83e1644d94bef76ef9807e17ad9189cc1d
parent0bd663a3804fceb3efb26a179e9c1d830ddcdb6e (diff)
patch 8.2.4176: Vim9: cannot use imported function with call()v8.2.4176
Problem: Vim9: cannot use imported function with call(). Solution: Translate the function name. (closes #9590)
-rw-r--r--src/evalfunc.c24
-rw-r--r--src/testdir/test_vim9_import.vim4
-rw-r--r--src/version.c2
3 files changed, 29 insertions, 1 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index f833512547..b838c395d6 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -2929,6 +2929,8 @@ f_call(typval_T *argvars, typval_T *rettv)
char_u *func;
partial_T *partial = NULL;
dict_T *selfdict = NULL;
+ char_u *dot;
+ char_u *tofree = NULL;
if (in_vim9script()
&& (check_for_string_or_func_arg(argvars, 0) == FAIL
@@ -2956,6 +2958,26 @@ f_call(typval_T *argvars, typval_T *rettv)
if (func == NULL || *func == NUL)
return; // type error, empty name or null function
+ dot = vim_strchr(func, '.');
+ if (dot != NULL)
+ {
+ imported_T *import = find_imported(func, dot - func, TRUE, NULL);
+
+ if (import != NULL && SCRIPT_ID_VALID(import->imp_sid))
+ {
+ scriptitem_T *si = SCRIPT_ITEM(import->imp_sid);
+
+ if (si->sn_autoload_prefix != NULL)
+ {
+ // Turn "import.Func" into "scriptname#Func".
+ tofree = concat_str(si->sn_autoload_prefix, dot + 1);
+ if (tofree == NULL)
+ return;
+ func = tofree;
+ }
+ }
+ }
+
if (argvars[2].v_type != VAR_UNKNOWN)
{
if (argvars[2].v_type != VAR_DICT)
@@ -2967,6 +2989,8 @@ f_call(typval_T *argvars, typval_T *rettv)
}
(void)func_call(func, &argvars[1], partial, selfdict, rettv);
+
+ vim_free(tofree);
}
/*
diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim
index 3734709f08..f06bea2c87 100644
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -706,7 +706,7 @@ def Test_use_autoload_import_in_fold_expression()
edit! otherfile
redraw
- set foldexpr= foldmethod&
+ set foldexpr= foldmethod& debug=
bwipe!
delete('Xdir', 'rf')
&rtp = save_rtp
@@ -1525,6 +1525,8 @@ def Test_vim9script_autoload_call()
call another.Getother()
assert_equal('other', g:result)
+
+ assert_equal('arg', call('another.RetArg', ['arg']))
END
CheckScriptSuccess(lines)
diff --git a/src/version.c b/src/version.c
index 728f724195..7f0dff5788 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 */
/**/
+ 4176,
+/**/
4175,
/**/
4174,