Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
23457:86b9697a8c63 | 23458:d2b1269c2c68 |
---|---|
3145 { | 3145 { |
3146 // can only redefine once | 3146 // can only redefine once |
3147 di->di_flags &= ~DI_FLAGS_RELOAD; | 3147 di->di_flags &= ~DI_FLAGS_RELOAD; |
3148 | 3148 |
3149 // A Vim9 script-local variable is also present in sn_all_vars and | 3149 // A Vim9 script-local variable is also present in sn_all_vars and |
3150 // sn_var_vals. | 3150 // sn_var_vals. It may set "type" from "tv". |
3151 if (is_script_local && vim9script) | 3151 if (is_script_local && vim9script) |
3152 update_vim9_script_var(FALSE, di, tv, type); | 3152 update_vim9_script_var(FALSE, di, tv, &type); |
3153 } | 3153 } |
3154 | 3154 |
3155 // existing variable, need to clear the value | 3155 // existing variable, need to clear the value |
3156 | 3156 |
3157 // Handle setting internal di: variables separately where needed to | 3157 // Handle setting internal di: variables separately where needed to |
3235 di->di_flags = DI_FLAGS_ALLOC; | 3235 di->di_flags = DI_FLAGS_ALLOC; |
3236 if (flags & (ASSIGN_CONST | ASSIGN_FINAL)) | 3236 if (flags & (ASSIGN_CONST | ASSIGN_FINAL)) |
3237 di->di_flags |= DI_FLAGS_LOCK; | 3237 di->di_flags |= DI_FLAGS_LOCK; |
3238 | 3238 |
3239 // A Vim9 script-local variable is also added to sn_all_vars and | 3239 // A Vim9 script-local variable is also added to sn_all_vars and |
3240 // sn_var_vals. | 3240 // sn_var_vals. It may set "type" from "tv". |
3241 if (is_script_local && vim9script) | 3241 if (is_script_local && vim9script) |
3242 update_vim9_script_var(TRUE, di, tv, type); | 3242 update_vim9_script_var(TRUE, di, tv, &type); |
3243 } | 3243 } |
3244 | 3244 |
3245 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) | 3245 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) |
3246 copy_tv(tv, &di->di_tv); | 3246 copy_tv(tv, &di->di_tv); |
3247 else | 3247 else |
3248 { | 3248 { |
3249 di->di_tv = *tv; | 3249 di->di_tv = *tv; |
3250 di->di_tv.v_lock = 0; | 3250 di->di_tv.v_lock = 0; |
3251 init_tv(tv); | 3251 init_tv(tv); |
3252 } | |
3253 | |
3254 if (vim9script && type != NULL) | |
3255 { | |
3256 if (type->tt_type == VAR_DICT && di->di_tv.vval.v_dict != NULL) | |
3257 di->di_tv.vval.v_dict->dv_type = alloc_type(type); | |
3258 else if (type->tt_type == VAR_LIST && di->di_tv.vval.v_list != NULL) | |
3259 di->di_tv.vval.v_list->lv_type = alloc_type(type); | |
3252 } | 3260 } |
3253 | 3261 |
3254 // ":const var = value" locks the value | 3262 // ":const var = value" locks the value |
3255 // ":final var = value" locks "var" | 3263 // ":final var = value" locks "var" |
3256 if (flags & ASSIGN_CONST) | 3264 if (flags & ASSIGN_CONST) |