0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.2.4698: Vim9: script variable has no flag that it was set

Problem:    Vim9: script variable has no flag that it was set.
Solution:   Add a flag that it was set, to avoid giving it a value when used.
            (closes #10088)
This commit is contained in:
Bram Moolenaar
2022-04-05 21:40:38 +01:00
parent 0d1f55c044
commit aa7d0c2335
7 changed files with 71 additions and 24 deletions

View File

@@ -2828,13 +2828,18 @@ eval_variable(
}
else if (rettv != NULL)
{
svar_T *sv = NULL;
int was_assigned = FALSE;
if (ht != NULL && ht == get_script_local_ht()
&& tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv)
{
svar_T *sv = find_typval_in_script(tv, 0, TRUE);
sv = find_typval_in_script(tv, 0, TRUE);
if (sv != NULL)
{
type = sv->sv_type;
was_assigned = sv->sv_flags & SVFLAG_ASSIGNED;
}
}
// If a list or dict variable wasn't initialized and has meaningful
@@ -2843,7 +2848,7 @@ eval_variable(
if (ht != &globvarht)
{
if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL
&& ((type != NULL && type != &t_dict_empty)
&& ((type != NULL && !was_assigned)
|| !in_vim9script()))
{
tv->vval.v_dict = dict_alloc();
@@ -2851,10 +2856,12 @@ eval_variable(
{
++tv->vval.v_dict->dv_refcount;
tv->vval.v_dict->dv_type = alloc_type(type);
if (sv != NULL)
sv->sv_flags |= SVFLAG_ASSIGNED;
}
}
else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL
&& ((type != NULL && type != &t_list_empty)
&& ((type != NULL && !was_assigned)
|| !in_vim9script()))
{
tv->vval.v_list = list_alloc();
@@ -2862,15 +2869,21 @@ eval_variable(
{
++tv->vval.v_list->lv_refcount;
tv->vval.v_list->lv_type = alloc_type(type);
if (sv != NULL)
sv->sv_flags |= SVFLAG_ASSIGNED;
}
}
else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL
&& ((type != NULL && type != &t_blob_null)
&& ((type != NULL && !was_assigned)
|| !in_vim9script()))
{
tv->vval.v_blob = blob_alloc();
if (tv->vval.v_blob != NULL)
{
++tv->vval.v_blob->bv_refcount;
if (sv != NULL)
sv->sv_flags |= SVFLAG_ASSIGNED;
}
}
}
copy_tv(tv, rettv);
@@ -3587,6 +3600,7 @@ set_var_const(
goto failed;
if (type == NULL)
type = sv->sv_type;
sv->sv_flags |= SVFLAG_ASSIGNED;
}
}