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/vim9class.c b/src/vim9class.c
index dc13c4b..cbb91f4 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -204,7 +204,13 @@
m->ocm_flags |= OCMFLAG_HAS_TYPE;
m->ocm_type = type;
if (init_expr != NULL)
+ {
m->ocm_init = init_expr;
+ // Save the script context, we need it when evaluating or compiling the
+ // initializer expression.
+ m->ocm_init_sctx = current_sctx;
+ m->ocm_init_sctx.sc_lnum += SOURCING_LNUM;
+ }
++gap->ga_len;
return OK;
}
@@ -1355,7 +1361,11 @@
typval_T *tv = &cl->class_members_tv[i];
if (m->ocm_init != NULL)
{
+ sctx_T save_current_sctx = current_sctx;
+
+ current_sctx = m->ocm_init_sctx;
typval_T *etv = eval_expr(m->ocm_init, eap);
+ current_sctx = save_current_sctx;
if (etv == NULL)
return FAIL;