patch 9.1.1146: Vim9: wrong context being used when evaluating class member
Problem: Vim9: wrong context being used when evaluating class member
(lifepillar, Ernie Rael)
Solution: Use the correct script context when evaluating a class member
init expression(Yegappan Lakshmanan)
fixes: #14011
fixes: #14402
closes: #15112
closes: #16660
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 65f6536..4b69dfa 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -6132,6 +6132,13 @@
clear_tv(STACK_TV_BOT(0));
ectx->ec_where = (where_T)WHERE_INIT;
break;
+
+ case ISN_SCRIPTCTX_SET:
+ // change the script context. Used to evaluate an object
+ // member variable initialization expression in the context of
+ // the script where the class is defined.
+ current_sctx = iptr->isn_arg.setsctx;
+ break;
}
continue;
@@ -6716,6 +6723,7 @@
int prev_current = 0;
int current;
int def_arg_idx = 0;
+ sctx_T script_ctx = current_sctx;
for (current = 0; current < instr_count; ++current)
{
@@ -6897,8 +6905,11 @@
scriptref_T *sref = iptr->isn_arg.script.scriptref;
scriptitem_T *si = SCRIPT_ITEM(sref->sref_sid);
svar_T *sv;
+ sctx_T save_sctx = current_sctx;
+ current_sctx = script_ctx;
sv = get_script_svar(sref, -1);
+ current_sctx = save_sctx;
if (sv == NULL)
smsg("%s%4d LOADSCRIPT [deleted] from %s",
pfx, current, si->sn_name);
@@ -7015,8 +7026,11 @@
scriptref_T *sref = iptr->isn_arg.script.scriptref;
scriptitem_T *si = SCRIPT_ITEM(sref->sref_sid);
svar_T *sv;
+ sctx_T save_sctx = current_sctx;
+ current_sctx = script_ctx;
sv = get_script_svar(sref, -1);
+ current_sctx = save_sctx;
if (sv == NULL)
smsg("%s%4d STORESCRIPT [deleted] in %s",
pfx, current, si->sn_name);
@@ -7650,6 +7664,15 @@
break;
case ISN_DROP: smsg("%s%4d DROP", pfx, current); break;
+ case ISN_SCRIPTCTX_SET:
+ {
+ int sid = iptr->isn_arg.setsctx.sc_sid;
+ scriptitem_T *si = SCRIPT_ITEM(sid);
+ smsg("%s%4d SCRIPTCTX_SET %s", pfx, current, si->sn_name);
+ script_ctx = iptr->isn_arg.setsctx;
+ }
+ break;
+
case ISN_FINISH: // End of list of instructions for ISN_SUBSTITUTE.
return;
}