Mercurial > vim
diff src/evalvars.c @ 23458:d2b1269c2c68 v8.2.2272
patch 8.2.2272: Vim9: extend() can violate the type of a variable
Commit: https://github.com/vim/vim/commit/aa210a3aeccc33c6051978017959126b037f94af
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 2 15:41:03 2021 +0100
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 Jan 2021 15:45:04 +0100 |
parents | a8e7acf71fa4 |
children | ce7d6b461660 |
line wrap: on
line diff
--- 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)