comparison src/evalfunc.c @ 27517:f00a7a2bee21 v8.2.4286

patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy() Commit: https://github.com/vim/vim/commit/381692b6f1c2ec9b73a139500286ddc9347a1c01 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 2 20:01:27 2022 +0000 patch 8.2.4286: Vim9: strict type checking after copy() and deepcopy() Problem: Vim9: strict type checking after copy() and deepcopy(). Solution: Allow type to change after making a copy. (closes https://github.com/vim/vim/issues/9644)
author Bram Moolenaar <Bram@vim.org>
date Wed, 02 Feb 2022 21:15:03 +0100
parents 4cea92e99a5a
children 4f1c67a5f446
comparison
equal deleted inserted replaced
27516:fdcbdd530e4c 27517:f00a7a2bee21
1168 return argtypes[0].type_curr; 1168 return argtypes[0].type_curr;
1169 } 1169 }
1170 return &t_void; 1170 return &t_void;
1171 } 1171 }
1172 static type_T * 1172 static type_T *
1173 ret_copy(int argcount,
1174 type2_T *argtypes,
1175 type_T **decl_type)
1176 {
1177 if (argcount > 0)
1178 {
1179 if (argtypes[0].type_decl != NULL)
1180 {
1181 if (argtypes[0].type_decl->tt_type == VAR_LIST)
1182 *decl_type = &t_list_any;
1183 else if (argtypes[0].type_decl->tt_type == VAR_DICT)
1184 *decl_type = &t_dict_any;
1185 else
1186 *decl_type = argtypes[0].type_decl;
1187 }
1188 if (argtypes[0].type_curr != NULL)
1189 {
1190 if (argtypes[0].type_curr->tt_type == VAR_LIST)
1191 return &t_list_any;
1192 else if (argtypes[0].type_curr->tt_type == VAR_DICT)
1193 return &t_dict_any;
1194 }
1195 return argtypes[0].type_curr;
1196 }
1197 return &t_void;
1198 }
1199 static type_T *
1173 ret_extend(int argcount, 1200 ret_extend(int argcount,
1174 type2_T *argtypes, 1201 type2_T *argtypes,
1175 type_T **decl_type) 1202 type_T **decl_type)
1176 { 1203 {
1177 if (argcount > 0) 1204 if (argcount > 0)
1569 {"complete_info", 0, 1, FEARG_1, arg1_list_string, 1596 {"complete_info", 0, 1, FEARG_1, arg1_list_string,
1570 ret_dict_any, f_complete_info}, 1597 ret_dict_any, f_complete_info},
1571 {"confirm", 1, 4, FEARG_1, arg4_string_string_number_string, 1598 {"confirm", 1, 4, FEARG_1, arg4_string_string_number_string,
1572 ret_number, f_confirm}, 1599 ret_number, f_confirm},
1573 {"copy", 1, 1, FEARG_1, NULL, 1600 {"copy", 1, 1, FEARG_1, NULL,
1574 ret_first_arg, f_copy}, 1601 ret_copy, f_copy},
1575 {"cos", 1, 1, FEARG_1, arg1_float_or_nr, 1602 {"cos", 1, 1, FEARG_1, arg1_float_or_nr,
1576 ret_float, FLOAT_FUNC(f_cos)}, 1603 ret_float, FLOAT_FUNC(f_cos)},
1577 {"cosh", 1, 1, FEARG_1, arg1_float_or_nr, 1604 {"cosh", 1, 1, FEARG_1, arg1_float_or_nr,
1578 ret_float, FLOAT_FUNC(f_cosh)}, 1605 ret_float, FLOAT_FUNC(f_cosh)},
1579 {"count", 2, 4, FEARG_1, arg24_count, 1606 {"count", 2, 4, FEARG_1, arg24_count,
1589 #else 1616 #else
1590 NULL 1617 NULL
1591 #endif 1618 #endif
1592 }, 1619 },
1593 {"deepcopy", 1, 2, FEARG_1, arg12_deepcopy, 1620 {"deepcopy", 1, 2, FEARG_1, arg12_deepcopy,
1594 ret_first_arg, f_deepcopy}, 1621 ret_copy, f_deepcopy},
1595 {"delete", 1, 2, FEARG_1, arg2_string, 1622 {"delete", 1, 2, FEARG_1, arg2_string,
1596 ret_number_bool, f_delete}, 1623 ret_number_bool, f_delete},
1597 {"deletebufline", 2, 3, FEARG_1, arg3_buffer_lnum_lnum, 1624 {"deletebufline", 2, 3, FEARG_1, arg3_buffer_lnum_lnum,
1598 ret_number_bool, f_deletebufline}, 1625 ret_number_bool, f_deletebufline},
1599 {"did_filetype", 0, 0, 0, NULL, 1626 {"did_filetype", 0, 0, 0, NULL,
3295 * "copy()" function 3322 * "copy()" function
3296 */ 3323 */
3297 static void 3324 static void
3298 f_copy(typval_T *argvars, typval_T *rettv) 3325 f_copy(typval_T *argvars, typval_T *rettv)
3299 { 3326 {
3300 item_copy(&argvars[0], rettv, FALSE, 0); 3327 item_copy(&argvars[0], rettv, FALSE, TRUE, 0);
3301 } 3328 }
3302 3329
3303 /* 3330 /*
3304 * Set the cursor position. 3331 * Set the cursor position.
3305 * If 'charcol' is TRUE, then use the column number as a character offset. 3332 * If 'charcol' is TRUE, then use the column number as a character offset.
3437 if (noref < 0 || noref > 1) 3464 if (noref < 0 || noref > 1)
3438 semsg(_(e_using_number_as_bool_nr), noref); 3465 semsg(_(e_using_number_as_bool_nr), noref);
3439 else 3466 else
3440 { 3467 {
3441 copyID = get_copyID(); 3468 copyID = get_copyID();
3442 item_copy(&argvars[0], rettv, TRUE, noref == 0 ? copyID : 0); 3469 item_copy(&argvars[0], rettv, TRUE, TRUE, noref == 0 ? copyID : 0);
3443 } 3470 }
3444 } 3471 }
3445 3472
3446 /* 3473 /*
3447 * "did_filetype()" function 3474 * "did_filetype()" function