comparison src/evalfunc.c @ 23588:510088f8c66f v8.2.2336

patch 8.2.2336: Vim9: not possible to extend dictionary with different type Commit: https://github.com/vim/vim/commit/b0e6b513648db7035046613431a4aa9d71ef4653 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jan 12 20:23:40 2021 +0100 patch 8.2.2336: Vim9: not possible to extend dictionary with different type Problem: Vim9: it is not possible to extend a dictionary with different item types. Solution: Add extendnew(). (closes #7666)
author Bram Moolenaar <Bram@vim.org>
date Tue, 12 Jan 2021 20:30:07 +0100
parents 34aa2907082a
children 2322b643e329
comparison
equal deleted inserted replaced
23587:901fb2bf09d1 23588:510088f8c66f
338 arg_type_mismatch(&t_list_any, type, context->arg_idx + 1); 338 arg_type_mismatch(&t_list_any, type, context->arg_idx + 1);
339 return FAIL; 339 return FAIL;
340 } 340 }
341 341
342 /* 342 /*
343 * Check "type" is the same type as the previous argument 343 * Check "type" is the same type as the previous argument.
344 * Must not be used for the first argcheck_T entry. 344 * Must not be used for the first argcheck_T entry.
345 */ 345 */
346 static int 346 static int
347 arg_same_as_prev(type_T *type, argcontext_T *context) 347 arg_same_as_prev(type_T *type, argcontext_T *context)
348 { 348 {
349 type_T *prev_type = context->arg_types[context->arg_idx - 1]; 349 type_T *prev_type = context->arg_types[context->arg_idx - 1];
350 350
351 return check_arg_type(prev_type, type, context->arg_idx + 1); 351 return check_arg_type(prev_type, type, context->arg_idx + 1);
352 }
353
354 /*
355 * Check "type" is the same basic type as the previous argument, checks list or
356 * dict vs other type, but not member type.
357 * Must not be used for the first argcheck_T entry.
358 */
359 static int
360 arg_same_struct_as_prev(type_T *type, argcontext_T *context)
361 {
362 type_T *prev_type = context->arg_types[context->arg_idx - 1];
363
364 if (prev_type->tt_type != context->arg_types[context->arg_idx]->tt_type)
365 return check_arg_type(prev_type, type, context->arg_idx + 1);
366 return OK;
352 } 367 }
353 368
354 /* 369 /*
355 * Check "type" is an item of the list or blob of the previous arg. 370 * Check "type" is an item of the list or blob of the previous arg.
356 * Must not be used for the first argcheck_T entry. 371 * Must not be used for the first argcheck_T entry.
392 * Lists of functions that check the argument types of a builtin function. 407 * Lists of functions that check the argument types of a builtin function.
393 */ 408 */
394 argcheck_T arg1_float_or_nr[] = {arg_float_or_nr}; 409 argcheck_T arg1_float_or_nr[] = {arg_float_or_nr};
395 argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev}; 410 argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev};
396 argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3}; 411 argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3};
412 argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, arg_extend3};
397 argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number}; 413 argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number};
398 414
399 /* 415 /*
400 * Functions that return the return type of a builtin function. 416 * Functions that return the return type of a builtin function.
401 * Note that "argtypes" is NULL if "argcount" is zero. 417 * Note that "argtypes" is NULL if "argcount" is zero.
875 ret_any, f_expand}, 891 ret_any, f_expand},
876 {"expandcmd", 1, 1, FEARG_1, NULL, 892 {"expandcmd", 1, 1, FEARG_1, NULL,
877 ret_string, f_expandcmd}, 893 ret_string, f_expandcmd},
878 {"extend", 2, 3, FEARG_1, arg23_extend, 894 {"extend", 2, 3, FEARG_1, arg23_extend,
879 ret_first_arg, f_extend}, 895 ret_first_arg, f_extend},
896 {"extendnew", 2, 3, FEARG_1, arg23_extendnew,
897 ret_first_cont, f_extendnew},
880 {"feedkeys", 1, 2, FEARG_1, NULL, 898 {"feedkeys", 1, 2, FEARG_1, NULL,
881 ret_void, f_feedkeys}, 899 ret_void, f_feedkeys},
882 {"file_readable", 1, 1, FEARG_1, NULL, // obsolete 900 {"file_readable", 1, 1, FEARG_1, NULL, // obsolete
883 ret_number, f_filereadable}, 901 ret_number, f_filereadable},
884 {"filereadable", 1, 1, FEARG_1, NULL, 902 {"filereadable", 1, 1, FEARG_1, NULL,