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/vim9expr.c b/src/vim9expr.c
index 76ce9c5..af12fb6 100644
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -538,12 +538,11 @@
cctx_T *cctx,
char_u *name, // variable NUL terminated
char_u *start, // start of variable
- char_u **end, // end of variable, may be NULL
- imported_T *import) // found imported item, can be NULL
+ char_u **end) // end of variable, may be NULL
{
scriptitem_T *si;
int idx;
- imported_T *imp;
+ imported_T *import;
if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
return FAIL;
@@ -558,14 +557,8 @@
return OK;
}
- if (end == NULL)
- imp = NULL;
- else if (import == NULL)
- imp = find_imported(name, 0, FALSE);
- else
- imp = import;
-
- if (imp != NULL)
+ import = end == NULL ? NULL : find_imported(name, 0, FALSE);
+ if (import != NULL)
{
char_u *p = skipwhite(*end);
char_u *exp_name;
@@ -575,8 +568,8 @@
int done = FALSE;
int res = OK;
- check_script_symlink(imp->imp_sid);
- import_check_sourced_sid(&imp->imp_sid);
+ check_script_symlink(import->imp_sid);
+ import_check_sourced_sid(&import->imp_sid);
// Need to lookup the member.
if (*p != '.')
@@ -598,11 +591,11 @@
cc = *p;
*p = NUL;
- si = SCRIPT_ITEM(imp->imp_sid);
+ si = SCRIPT_ITEM(import->imp_sid);
if (si->sn_import_autoload && si->sn_state == SN_STATE_NOT_LOADED)
// "import autoload './dir/script.vim'" or
// "import autoload './autoload/script.vim'" - load script first
- res = generate_SOURCE(cctx, imp->imp_sid);
+ res = generate_SOURCE(cctx, import->imp_sid);
if (res == OK)
{
@@ -631,17 +624,17 @@
{
char_u sid_name[MAX_FUNC_NAME_LEN];
- func_name_with_sid(exp_name, imp->imp_sid, sid_name);
+ func_name_with_sid(exp_name, import->imp_sid, sid_name);
res = generate_PUSHFUNC(cctx, sid_name, &t_func_any, TRUE);
}
else
res = generate_OLDSCRIPT(cctx, ISN_LOADEXPORT, exp_name,
- imp->imp_sid, &t_any);
+ import->imp_sid, &t_any);
done = TRUE;
}
else
{
- idx = find_exported(imp->imp_sid, exp_name, &ufunc, &type,
+ idx = find_exported(import->imp_sid, exp_name, &ufunc, &type,
cctx, NULL, TRUE);
}
}
@@ -663,7 +656,7 @@
}
generate_VIM9SCRIPT(cctx, ISN_LOADSCRIPT,
- imp->imp_sid,
+ import->imp_sid,
idx,
type);
return OK;
@@ -778,7 +771,7 @@
res = generate_funcref(cctx, name, FALSE);
else
res = compile_load_scriptvar(cctx, name,
- NULL, &end, NULL);
+ NULL, &end);
break;
case 'g': if (vim_strchr(name, AUTOLOAD_CHAR) == NULL)
{
@@ -894,15 +887,11 @@
}
else
{
- imported_T *imp = NULL;
-
// "var" can be script-local even without using "s:" if it
// already exists in a Vim9 script or when it's imported.
if (script_var_exists(*arg, len, cctx, NULL) == OK
- || (imp = find_imported(name, 0, FALSE)) != NULL
- || (imp = find_imported_from_extends(cctx, name, 0, FALSE))
- != NULL)
- res = compile_load_scriptvar(cctx, name, *arg, &end, imp);
+ || find_imported(name, 0, FALSE) != NULL)
+ res = compile_load_scriptvar(cctx, name, *arg, &end);
// When evaluating an expression and the name starts with an
// uppercase letter it can be a user defined function.