summaryrefslogtreecommitdiff
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-01-02 15:41:03 +0100
committerBram Moolenaar <Bram@vim.org>2021-01-02 15:41:03 +0100
commitaa210a3aeccc33c6051978017959126b037f94af (patch)
tree29c2f91c51dc55a52e427f89643ae4b9c4c56c58 /src/evalvars.c
parent3e0107ea16349b354e0e9712e95b09ef019e99e5 (diff)
downloadvim-git-aa210a3aeccc33c6051978017959126b037f94af.tar.gz
patch 8.2.2272: Vim9: extend() can violate the type of a variablev8.2.2272
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)
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c16
1 files changed, 12 insertions, 4 deletions
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)