diff 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
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -340,7 +340,7 @@ arg_list_or_dict(type_T *type, argcontex
 }
 
 /*
- * Check "type" is the same type as the previous argument
+ * Check "type" is the same type as the previous argument.
  * Must not be used for the first argcheck_T entry.
  */
     static int
@@ -352,6 +352,21 @@ arg_same_as_prev(type_T *type, argcontex
 }
 
 /*
+ * Check "type" is the same basic type as the previous argument, checks list or
+ * dict vs other type, but not member type.
+ * Must not be used for the first argcheck_T entry.
+ */
+    static int
+arg_same_struct_as_prev(type_T *type, argcontext_T *context)
+{
+    type_T *prev_type = context->arg_types[context->arg_idx - 1];
+
+    if (prev_type->tt_type != context->arg_types[context->arg_idx]->tt_type)
+	return check_arg_type(prev_type, type, context->arg_idx + 1);
+    return OK;
+}
+
+/*
  * Check "type" is an item of the list or blob of the previous arg.
  * Must not be used for the first argcheck_T entry.
  */
@@ -394,6 +409,7 @@ arg_extend3(type_T *type, argcontext_T *
 argcheck_T arg1_float_or_nr[] = {arg_float_or_nr};
 argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev};
 argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3};
+argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, arg_extend3};
 argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number};
 
 /*
@@ -877,6 +893,8 @@ static funcentry_T global_functions[] =
 			ret_string,	    f_expandcmd},
     {"extend",		2, 3, FEARG_1,	    arg23_extend,
 			ret_first_arg,	    f_extend},
+    {"extendnew",	2, 3, FEARG_1,	    arg23_extendnew,
+			ret_first_cont,	    f_extendnew},
     {"feedkeys",	1, 2, FEARG_1,	    NULL,
 			ret_void,	    f_feedkeys},
     {"file_readable",	1, 1, FEARG_1,	    NULL,	// obsolete