summaryrefslogtreecommitdiff
path: root/src/list.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-01-03 16:52:28 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-03 16:52:28 +0000
commitad8f2485856eadb931ebd1f633ca366a40e415b8 (patch)
tree938bba2d4c81e2ec5b1e97a9ca5dd74a3fc09ab3 /src/list.c
parentc88e977862ba6477a3b5b28706c45f96069a3073 (diff)
downloadvim-git-ad8f2485856eadb931ebd1f633ca366a40e415b8.tar.gz
patch 8.2.3994: Vim9: extend() complains about type when it was not declaredv8.2.3994
Problem: Vim9: extend() complains about the type even when it was not declared. Solution: Only check the list or dict type when it was declared.
Diffstat (limited to 'src/list.c')
-rw-r--r--src/list.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/list.c b/src/list.c
index 6b275789d..aadc7233d 100644
--- a/src/list.c
+++ b/src/list.c
@@ -2758,25 +2758,26 @@ list_extend_func(
extend(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg, int is_new)
{
type_T *type = NULL;
- garray_T type_list;
char *func_name = is_new ? "extendnew()" : "extend()";
- if (!is_new && in_vim9script())
- {
- // Check that extend() does not change the type of the dict.
- ga_init2(&type_list, sizeof(type_T *), 10);
- type = typval2type(argvars, get_copyID(), &type_list, TVTT_DO_MEMBER);
- }
-
if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST)
+ {
+ // Check that extend() does not change the type of the list if it was
+ // declared.
+ if (!is_new && in_vim9script() && argvars[0].vval.v_list != NULL)
+ type = argvars[0].vval.v_list->lv_type;
list_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv);
+ }
else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT)
+ {
+ // Check that extend() does not change the type of the list if it was
+ // declared.
+ if (!is_new && in_vim9script() && argvars[0].vval.v_dict != NULL)
+ type = argvars[0].vval.v_dict->dv_type;
dict_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv);
+ }
else
semsg(_(e_argument_of_str_must_be_list_or_dictionary), func_name);
-
- if (type != NULL)
- clear_type_list(&type_list);
}
/*