Mercurial > vim
diff src/vim9script.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 | 4003fc2340dc |
children | b115b552071f |
line wrap: on
line diff
--- a/src/vim9script.c +++ b/src/vim9script.c @@ -999,35 +999,29 @@ find_typval_in_script(typval_T *dest) */ int check_script_var_type( - typval_T *dest, + svar_T *sv, typval_T *value, char_u *name, where_T where) { - svar_T *sv = find_typval_in_script(dest); int ret; - if (sv != NULL) + if (sv->sv_const != 0) + { + semsg(_(e_cannot_change_readonly_variable_str), name); + return FAIL; + } + ret = check_typval_type(sv->sv_type, value, where); + if (ret == OK && need_convert_to_bool(sv->sv_type, value)) { - if (sv->sv_const != 0) - { - semsg(_(e_cannot_change_readonly_variable_str), name); - return FAIL; - } - ret = check_typval_type(sv->sv_type, value, where); - if (ret == OK && need_convert_to_bool(sv->sv_type, value)) - { - int val = tv2bool(value); + int val = tv2bool(value); - clear_tv(value); - value->v_type = VAR_BOOL; - value->v_lock = 0; - value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE; - } - return ret; + clear_tv(value); + value->v_type = VAR_BOOL; + value->v_lock = 0; + value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE; } - - return OK; // not really + return ret; } // words that cannot be used as a variable