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.
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 0e8a1dd..da2822c 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1658,6 +1658,29 @@
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 @@
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, ¬used)
== FAIL)
- {
- semsg(_(e_cant_open_file_str), si->sn_name);
- goto on_error;
- }
- }
+ goto on_error;
}
break;