mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.3128: Vim9: uninitialzed list does not get type checked
Problem: Vim9: uninitialzed list does not get type checked. Solution: Set the type when initializing the variable. (closes #8529)
This commit is contained in:
@@ -959,7 +959,7 @@ get_lval(
|
|||||||
&& lp->ll_tv == &v->di_tv
|
&& lp->ll_tv == &v->di_tv
|
||||||
&& ht != NULL && ht == get_script_local_ht())
|
&& ht != NULL && ht == get_script_local_ht())
|
||||||
{
|
{
|
||||||
svar_T *sv = find_typval_in_script(lp->ll_tv);
|
svar_T *sv = find_typval_in_script(lp->ll_tv, TRUE);
|
||||||
|
|
||||||
// Vim9 script local variable: get the type
|
// Vim9 script local variable: get the type
|
||||||
if (sv != NULL)
|
if (sv != NULL)
|
||||||
|
@@ -2565,6 +2565,7 @@ eval_variable(
|
|||||||
typval_T *tv = NULL;
|
typval_T *tv = NULL;
|
||||||
int found = FALSE;
|
int found = FALSE;
|
||||||
dictitem_T *v;
|
dictitem_T *v;
|
||||||
|
hashtab_T *ht = NULL;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
// truncate the name, so that we can use strcmp()
|
// truncate the name, so that we can use strcmp()
|
||||||
@@ -2575,7 +2576,7 @@ eval_variable(
|
|||||||
if ((tv = lookup_debug_var(name)) == NULL)
|
if ((tv = lookup_debug_var(name)) == NULL)
|
||||||
{
|
{
|
||||||
// Check for user-defined variables.
|
// Check for user-defined variables.
|
||||||
v = find_var(name, NULL, flags & EVAL_VAR_NOAUTOLOAD);
|
v = find_var(name, &ht, flags & EVAL_VAR_NOAUTOLOAD);
|
||||||
if (v != NULL)
|
if (v != NULL)
|
||||||
{
|
{
|
||||||
tv = &v->di_tv;
|
tv = &v->di_tv;
|
||||||
@@ -2655,18 +2656,35 @@ eval_variable(
|
|||||||
}
|
}
|
||||||
else if (rettv != NULL)
|
else if (rettv != NULL)
|
||||||
{
|
{
|
||||||
|
type_T *type = NULL;
|
||||||
|
|
||||||
|
if (ht != NULL && ht == get_script_local_ht())
|
||||||
|
{
|
||||||
|
svar_T *sv = find_typval_in_script(tv, FALSE);
|
||||||
|
|
||||||
|
// TODO: check imported variable
|
||||||
|
if (sv != NULL)
|
||||||
|
type = sv->sv_type;
|
||||||
|
}
|
||||||
|
|
||||||
// If a list or dict variable wasn't initialized, do it now.
|
// If a list or dict variable wasn't initialized, do it now.
|
||||||
if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL)
|
if (tv->v_type == VAR_DICT && tv->vval.v_dict == NULL)
|
||||||
{
|
{
|
||||||
tv->vval.v_dict = dict_alloc();
|
tv->vval.v_dict = dict_alloc();
|
||||||
if (tv->vval.v_dict != NULL)
|
if (tv->vval.v_dict != NULL)
|
||||||
|
{
|
||||||
++tv->vval.v_dict->dv_refcount;
|
++tv->vval.v_dict->dv_refcount;
|
||||||
|
tv->vval.v_dict->dv_type = alloc_type(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL)
|
else if (tv->v_type == VAR_LIST && tv->vval.v_list == NULL)
|
||||||
{
|
{
|
||||||
tv->vval.v_list = list_alloc();
|
tv->vval.v_list = list_alloc();
|
||||||
if (tv->vval.v_list != NULL)
|
if (tv->vval.v_list != NULL)
|
||||||
|
{
|
||||||
++tv->vval.v_list->lv_refcount;
|
++tv->vval.v_list->lv_refcount;
|
||||||
|
tv->vval.v_list->lv_type = alloc_type(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL)
|
else if (tv->v_type == VAR_BLOB && tv->vval.v_blob == NULL)
|
||||||
{
|
{
|
||||||
|
@@ -16,7 +16,7 @@ char_u *vim9_declare_scriptvar(exarg_T *eap, char_u *arg);
|
|||||||
void update_vim9_script_var(int create, dictitem_T *di, int flags, typval_T *tv, type_T **type, int do_member);
|
void update_vim9_script_var(int create, dictitem_T *di, int flags, typval_T *tv, type_T **type, int do_member);
|
||||||
void hide_script_var(scriptitem_T *si, int idx, int func_defined);
|
void hide_script_var(scriptitem_T *si, int idx, int func_defined);
|
||||||
void free_all_script_vars(scriptitem_T *si);
|
void free_all_script_vars(scriptitem_T *si);
|
||||||
svar_T *find_typval_in_script(typval_T *dest);
|
svar_T *find_typval_in_script(typval_T *dest, int give_error);
|
||||||
int check_script_var_type(typval_T *dest, typval_T *value, char_u *name, where_T where);
|
int check_script_var_type(typval_T *dest, typval_T *value, char_u *name, where_T where);
|
||||||
int check_reserved_name(char_u *name);
|
int check_reserved_name(char_u *name);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -111,6 +111,13 @@ def Test_add_list()
|
|||||||
l->add(123)
|
l->add(123)
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
|
CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
var l: list<string>
|
||||||
|
l->add(123)
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1012: Type mismatch; expected string but got number', 3)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_add_blob()
|
def Test_add_blob()
|
||||||
|
@@ -1512,7 +1512,7 @@ deref_func_name(
|
|||||||
{
|
{
|
||||||
if (type != NULL && ht == get_script_local_ht())
|
if (type != NULL && ht == get_script_local_ht())
|
||||||
{
|
{
|
||||||
svar_T *sv = find_typval_in_script(&v->di_tv);
|
svar_T *sv = find_typval_in_script(&v->di_tv, TRUE);
|
||||||
|
|
||||||
if (sv != NULL)
|
if (sv != NULL)
|
||||||
*type = sv->sv_type;
|
*type = sv->sv_type;
|
||||||
|
@@ -755,6 +755,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3128,
|
||||||
/**/
|
/**/
|
||||||
3127,
|
3127,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -806,7 +806,7 @@ update_vim9_script_var(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sv = find_typval_in_script(&di->di_tv);
|
sv = find_typval_in_script(&di->di_tv, TRUE);
|
||||||
}
|
}
|
||||||
if (sv != NULL)
|
if (sv != NULL)
|
||||||
{
|
{
|
||||||
@@ -922,10 +922,11 @@ free_all_script_vars(scriptitem_T *si)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the script-local variable that links to "dest".
|
* Find the script-local variable that links to "dest".
|
||||||
* Returns NULL if not found.
|
* Returns NULL if not found and when "give_error" is TRUE this is considered
|
||||||
|
* an internal error.
|
||||||
*/
|
*/
|
||||||
svar_T *
|
svar_T *
|
||||||
find_typval_in_script(typval_T *dest)
|
find_typval_in_script(typval_T *dest, int give_error)
|
||||||
{
|
{
|
||||||
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
|
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
|
||||||
int idx;
|
int idx;
|
||||||
@@ -944,6 +945,7 @@ find_typval_in_script(typval_T *dest)
|
|||||||
if (sv->sv_name != NULL && sv->sv_tv == dest)
|
if (sv->sv_name != NULL && sv->sv_tv == dest)
|
||||||
return sv;
|
return sv;
|
||||||
}
|
}
|
||||||
|
if (give_error)
|
||||||
iemsg("find_typval_in_script(): not found");
|
iemsg("find_typval_in_script(): not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -959,7 +961,7 @@ check_script_var_type(
|
|||||||
char_u *name,
|
char_u *name,
|
||||||
where_T where)
|
where_T where)
|
||||||
{
|
{
|
||||||
svar_T *sv = find_typval_in_script(dest);
|
svar_T *sv = find_typval_in_script(dest, TRUE);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (sv != NULL)
|
if (sv != NULL)
|
||||||
|
Reference in New Issue
Block a user