From aa210a3aeccc33c6051978017959126b037f94af Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 2 Jan 2021 15:41:03 +0100 Subject: patch 8.2.2272: Vim9: extend() can violate the type of a variable Problem: Vim9: extend() can violate the type of a variable. Solution: Add the type to the dictionary or list and check items against it. (closes #7593) --- src/evalvars.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/evalvars.c') diff --git a/src/evalvars.c b/src/evalvars.c index 94b857ed9..7fb190c3d 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -3147,9 +3147,9 @@ set_var_const( di->di_flags &= ~DI_FLAGS_RELOAD; // A Vim9 script-local variable is also present in sn_all_vars and - // sn_var_vals. + // sn_var_vals. It may set "type" from "tv". if (is_script_local && vim9script) - update_vim9_script_var(FALSE, di, tv, type); + update_vim9_script_var(FALSE, di, tv, &type); } // existing variable, need to clear the value @@ -3237,9 +3237,9 @@ set_var_const( di->di_flags |= DI_FLAGS_LOCK; // A Vim9 script-local variable is also added to sn_all_vars and - // sn_var_vals. + // sn_var_vals. It may set "type" from "tv". if (is_script_local && vim9script) - update_vim9_script_var(TRUE, di, tv, type); + update_vim9_script_var(TRUE, di, tv, &type); } if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) @@ -3251,6 +3251,14 @@ set_var_const( init_tv(tv); } + if (vim9script && type != NULL) + { + if (type->tt_type == VAR_DICT && di->di_tv.vval.v_dict != NULL) + di->di_tv.vval.v_dict->dv_type = alloc_type(type); + else if (type->tt_type == VAR_LIST && di->di_tv.vval.v_list != NULL) + di->di_tv.vval.v_list->lv_type = alloc_type(type); + } + // ":const var = value" locks the value // ":final var = value" locks "var" if (flags & ASSIGN_CONST) -- cgit v1.2.1