comparison 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
comparison
equal deleted inserted replaced
26301:cfab63c48045 26302:7351926fbe9e
997 * Check if the type of script variable "dest" allows assigning "value". 997 * Check if the type of script variable "dest" allows assigning "value".
998 * If needed convert "value" to a bool. 998 * If needed convert "value" to a bool.
999 */ 999 */
1000 int 1000 int
1001 check_script_var_type( 1001 check_script_var_type(
1002 typval_T *dest, 1002 svar_T *sv,
1003 typval_T *value, 1003 typval_T *value,
1004 char_u *name, 1004 char_u *name,
1005 where_T where) 1005 where_T where)
1006 { 1006 {
1007 svar_T *sv = find_typval_in_script(dest);
1008 int ret; 1007 int ret;
1009 1008
1010 if (sv != NULL) 1009 if (sv->sv_const != 0)
1011 { 1010 {
1012 if (sv->sv_const != 0) 1011 semsg(_(e_cannot_change_readonly_variable_str), name);
1013 { 1012 return FAIL;
1014 semsg(_(e_cannot_change_readonly_variable_str), name); 1013 }
1015 return FAIL; 1014 ret = check_typval_type(sv->sv_type, value, where);
1016 } 1015 if (ret == OK && need_convert_to_bool(sv->sv_type, value))
1017 ret = check_typval_type(sv->sv_type, value, where); 1016 {
1018 if (ret == OK && need_convert_to_bool(sv->sv_type, value)) 1017 int val = tv2bool(value);
1019 { 1018
1020 int val = tv2bool(value); 1019 clear_tv(value);
1021 1020 value->v_type = VAR_BOOL;
1022 clear_tv(value); 1021 value->v_lock = 0;
1023 value->v_type = VAR_BOOL; 1022 value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE;
1024 value->v_lock = 0; 1023 }
1025 value->vval.v_number = val ? VVAL_TRUE : VVAL_FALSE; 1024 return ret;
1026 }
1027 return ret;
1028 }
1029
1030 return OK; // not really
1031 } 1025 }
1032 1026
1033 // words that cannot be used as a variable 1027 // words that cannot be used as a variable
1034 static char *reserved[] = { 1028 static char *reserved[] = {
1035 "true", 1029 "true",