Mercurial > vim
diff src/evalvars.c @ 26302:7351926fbe9e v8.2.3682
patch 8.2.3682: Vim9: assigning to a script variable drops the type
Commit: https://github.com/vim/vim/commit/7824fc80f675b8098e6483ce082e287aad14b6da
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Nov 26 17:36:51 2021 +0000
patch 8.2.3682: Vim9: assigning to a script variable drops the type
Problem: Vim9: assigning to a script variable drops the required type.
Solution: Lookup the type of the variable and use it. (closes https://github.com/vim/vim/issues/9219)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 26 Nov 2021 18:45:03 +0100 |
parents | 640b62dbf6cb |
children | f44ce6a85c34 |
line wrap: on
line diff
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -3206,13 +3206,14 @@ set_var( void set_var_const( char_u *name, - type_T *type, + type_T *type_arg, typval_T *tv_arg, int copy, // make copy of value in "tv" int flags_arg, // ASSIGN_CONST, ASSIGN_FINAL, etc. int var_idx) // index for ":let [a, b] = list" { typval_T *tv = tv_arg; + type_T *type = type_arg; typval_T bool_tv; dictitem_T *di; typval_T *dest_tv = NULL; @@ -3334,13 +3335,18 @@ set_var_const( if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0) { where_T where = WHERE_INIT; - - // check the type and adjust to bool if needed - where.wt_index = var_idx; - where.wt_variable = TRUE; - if (check_script_var_type(&di->di_tv, tv, name, where) - == FAIL) - goto failed; + svar_T *sv = find_typval_in_script(&di->di_tv); + + if (sv != NULL) + { + // check the type and adjust to bool if needed + where.wt_index = var_idx; + where.wt_variable = TRUE; + if (check_script_var_type(sv, tv, name, where) == FAIL) + goto failed; + if (type == NULL) + type = sv->sv_type; + } } if ((flags & ASSIGN_FOR_LOOP) == 0