0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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 #9219)
This commit is contained in:
Bram Moolenaar
2021-11-26 17:36:51 +00:00
parent bfc5786a61
commit 7824fc80f6
5 changed files with 40 additions and 28 deletions

View File

@@ -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)
{
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);
clear_tv(value);
value->v_type = VAR_BOOL;
value->v_lock = 0;
value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE;
}
return ret;
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);
return OK; // not really
clear_tv(value);
value->v_type = VAR_BOOL;
value->v_lock = 0;
value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE;
}
return ret;
}
// words that cannot be used as a variable