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/vim9instr.c b/src/vim9instr.c
index b519039..86fddd9 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -2506,6 +2506,23 @@
return OK;
}
+/*
+ * Generate instruction to set the script context. Used to evaluate an
+ * object member variable initialization expression in the context of the
+ * script where the class is defined.
+ */
+ int
+generate_SCRIPTCTX_SET(cctx_T *cctx, sctx_T new_sctx)
+{
+ isn_T *isn;
+
+ RETURN_OK_IF_SKIP(cctx);
+ if ((isn = generate_instr(cctx, ISN_SCRIPTCTX_SET)) == NULL)
+ return FAIL;
+ isn->isn_arg.setsctx = new_sctx;
+ return OK;
+}
+
#if defined(FEAT_PROFILE) || defined(PROTO)
void
may_generate_prof_end(cctx_T *cctx, int prof_lnum)
@@ -2821,6 +2838,7 @@
case ISN_UNPACK:
case ISN_USEDICT:
case ISN_WHILE:
+ case ISN_SCRIPTCTX_SET:
// nothing allocated
break;
}