diff src/evalfunc.c @ 27295:69aa20a6e7ae v8.2.4176

patch 8.2.4176: Vim9: cannot use imported function with call() Commit: https://github.com/vim/vim/commit/3d8e25a6d2660432df033cdad29f981ffe6ae0fc Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 22 11:00:02 2022 +0000 patch 8.2.4176: Vim9: cannot use imported function with call() Problem: Vim9: cannot use imported function with call(). Solution: Translate the function name. (closes https://github.com/vim/vim/issues/9590)
author Bram Moolenaar <Bram@vim.org>
date Sat, 22 Jan 2022 12:15:03 +0100
parents e91b577be192
children ec2ba9acec1b
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -2929,6 +2929,8 @@ f_call(typval_T *argvars, typval_T *rett
     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 *rett
     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 *rett
     }
 
     (void)func_call(func, &argvars[1], partial, selfdict, rettv);
+
+    vim_free(tofree);
 }
 
 /*