patch 8.2.1154: Vim9: crash when using imported function
Problem: Vim9: crash when using imported function.
Solution: Check for a function type. Set the script context when calling a
function. (closes #6412)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 7afa3fc..a3cea80 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -160,6 +160,7 @@
int arg_to_add;
int vararg_count = 0;
int idx;
+ estack_T *entry;
if (dfunc->df_deleted)
{
@@ -230,7 +231,14 @@
// Set execution state to the start of the called function.
ectx->ec_dfunc_idx = cdf_idx;
ectx->ec_instr = dfunc->df_instr;
- estack_push_ufunc(dfunc->df_ufunc, 1);
+ entry = estack_push_ufunc(dfunc->df_ufunc, 1);
+ if (entry != NULL)
+ {
+ // Set the script context to the script where the function was defined.
+ // TODO: save more than the SID?
+ entry->es_save_sid = current_sctx.sc_sid;
+ current_sctx.sc_sid = ufunc->uf_script_ctx.sc_sid;
+ }
// Decide where to start execution, handles optional arguments.
init_instr_idx(ufunc, argcount, ectx);
@@ -386,9 +394,12 @@
+ ectx->ec_dfunc_idx;
int argcount = ufunc_argcount(dfunc->df_ufunc);
int top = ectx->ec_frame_idx - argcount;
+ estack_T *entry;
// execution context goes one level up
- estack_pop();
+ entry = estack_pop();
+ if (entry != NULL)
+ current_sctx.sc_sid = entry->es_save_sid;
if (handle_closure_in_use(ectx, TRUE) == FAIL)
return FAIL;