diff src/userfunc.c @ 20816:9faab49c880f v8.2.0960

patch 8.2.0960: cannot use :import in legacy Vim script Commit: https://github.com/vim/vim/commit/9721fb4ea3db2559aaf7f71458da8ddda30ff93e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jun 11 23:10:46 2020 +0200 patch 8.2.0960: cannot use :import in legacy Vim script Problem: Cannot use :import in legacy Vim script. Solution: Support :import in any Vim script.
author Bram Moolenaar <Bram@vim.org>
date Thu, 11 Jun 2020 23:15:03 +0200
parents a2262c80a4e0
children 9064044fd4f6
line wrap: on
line diff
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -719,20 +719,45 @@ find_func_even_dead(char_u *name, int is
     ufunc_T	*func;
     imported_T	*imported;
 
-    if (in_vim9script() && !is_global)
+    if (!is_global)
     {
-	// Find script-local function before global one.
-	func = find_func_with_sid(name, current_sctx.sc_sid);
-	if (func != NULL)
-	    return func;
-
-	// Find imported funcion before global one.
-	imported = find_imported(name, 0, cctx);
-	if (imported != NULL && imported->imp_funcname != NULL)
+	char_u *after_script = NULL;
+
+	if (in_vim9script())
+	{
+	    // Find script-local function before global one.
+	    func = find_func_with_sid(name, current_sctx.sc_sid);
+	    if (func != NULL)
+		return func;
+	}
+
+	if (!in_vim9script()
+		&& name[0] == K_SPECIAL
+		&& name[1] == KS_EXTRA
+		&& name[2] == KE_SNR)
 	{
-	    hi = hash_find(&func_hashtab, imported->imp_funcname);
-	    if (!HASHITEM_EMPTY(hi))
-		return HI2UF(hi);
+	    long sid;
+
+	    // Caller changes s: to <SNR>99_name.
+
+	    after_script = name + 3;
+	    sid = getdigits(&after_script);
+	    if (sid == current_sctx.sc_sid && *after_script == '_')
+		++after_script;
+	    else
+		after_script = NULL;
+	}
+	if (in_vim9script() || after_script != NULL)
+	{
+	    // Find imported function before global one.
+	    imported = find_imported(
+			  after_script == NULL ? name : after_script, 0, cctx);
+	    if (imported != NULL && imported->imp_funcname != NULL)
+	    {
+		hi = hash_find(&func_hashtab, imported->imp_funcname);
+		if (!HASHITEM_EMPTY(hi))
+		    return HI2UF(hi);
+	    }
 	}
     }