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)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 1abcd5e..0d17b9e 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -340,7 +340,7 @@
}
/*
- * 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 @@
}
/*
+ * 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 @@
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 @@
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