diff src/vim9execute.c @ 28447:6f753a8125f0 v8.2.4748

patch 8.2.4748: cannot use an imported function in a mapping Commit: https://github.com/vim/vim/commit/8944551534b311a2d25acf6e8db235c6d906256c Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 14 12:58:23 2022 +0100 patch 8.2.4748: cannot use an imported function in a mapping Problem: Cannot use an imported function in a mapping. Solution: Recognize <SID>name.Func.
author Bram Moolenaar <Bram@vim.org>
date Thu, 14 Apr 2022 14:00:05 +0200
parents fabe722b24e9
children 52ef65c0637f
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1658,6 +1658,29 @@ exec_command(isn_T *iptr)
     return OK;
 }
 
+/*
+ * If script "sid" is not loaded yet then load it now.
+ * Caller must make sure "sid" is a valid script ID.
+ * "loaded" is set to TRUE if the script had to be loaded.
+ * Returns FAIL if loading fails, OK if already loaded or loaded now.
+ */
+    int
+may_load_script(int sid, int *loaded)
+{
+    scriptitem_T *si = SCRIPT_ITEM(sid);
+
+    if (si->sn_state == SN_STATE_NOT_LOADED)
+    {
+	*loaded = TRUE;
+	if (do_source(si->sn_name, FALSE, DOSO_NONE, NULL) == FAIL)
+	{
+	    semsg(_(e_cant_open_file_str), si->sn_name);
+	    return FAIL;
+	}
+    }
+    return OK;
+}
+
 // used for v_instr of typval of VAR_INSTR
 struct instr_S {
     ectx_T	*instr_ectx;
@@ -2632,18 +2655,11 @@ exec_instructions(ectx_T *ectx)
 
 	    case ISN_SOURCE:
 		{
-		    scriptitem_T *si = SCRIPT_ITEM(iptr->isn_arg.number);
-
-		    if (si->sn_state == SN_STATE_NOT_LOADED)
-		    {
-			SOURCING_LNUM = iptr->isn_lnum;
-			if (do_source(si->sn_name, FALSE, DOSO_NONE, NULL)
+		    int notused;
+		    SOURCING_LNUM = iptr->isn_lnum;
+		    if (may_load_script((int)iptr->isn_arg.number, &notused)
 								       == FAIL)
-			{
-			    semsg(_(e_cant_open_file_str), si->sn_name);
-			    goto on_error;
-			}
-		    }
+			goto on_error;
 		}
 		break;