Mercurial > vim
comparison src/list.c @ 26931:6cdf92e77a91 v8.2.3994
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
Commit: https://github.com/vim/vim/commit/ad8f2485856eadb931ebd1f633ca366a40e415b8
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Jan 3 16:52:28 2022 +0000
patch 8.2.3994: Vim9: extend() complains about type when it was not declared
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 03 Jan 2022 18:00:03 +0100 |
parents | 4e77f9961650 |
children | ccb9be1cdd71 |
comparison
equal
deleted
inserted
replaced
26930:a84aeabd7722 | 26931:6cdf92e77a91 |
---|---|
2756 */ | 2756 */ |
2757 static void | 2757 static void |
2758 extend(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg, int is_new) | 2758 extend(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg, int is_new) |
2759 { | 2759 { |
2760 type_T *type = NULL; | 2760 type_T *type = NULL; |
2761 garray_T type_list; | |
2762 char *func_name = is_new ? "extendnew()" : "extend()"; | 2761 char *func_name = is_new ? "extendnew()" : "extend()"; |
2763 | 2762 |
2764 if (!is_new && in_vim9script()) | |
2765 { | |
2766 // Check that extend() does not change the type of the dict. | |
2767 ga_init2(&type_list, sizeof(type_T *), 10); | |
2768 type = typval2type(argvars, get_copyID(), &type_list, TVTT_DO_MEMBER); | |
2769 } | |
2770 | |
2771 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) | 2763 if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_LIST) |
2764 { | |
2765 // Check that extend() does not change the type of the list if it was | |
2766 // declared. | |
2767 if (!is_new && in_vim9script() && argvars[0].vval.v_list != NULL) | |
2768 type = argvars[0].vval.v_list->lv_type; | |
2772 list_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv); | 2769 list_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv); |
2770 } | |
2773 else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT) | 2771 else if (argvars[0].v_type == VAR_DICT && argvars[1].v_type == VAR_DICT) |
2772 { | |
2773 // Check that extend() does not change the type of the list if it was | |
2774 // declared. | |
2775 if (!is_new && in_vim9script() && argvars[0].vval.v_dict != NULL) | |
2776 type = argvars[0].vval.v_dict->dv_type; | |
2774 dict_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv); | 2777 dict_extend_func(argvars, type, func_name, arg_errmsg, is_new, rettv); |
2778 } | |
2775 else | 2779 else |
2776 semsg(_(e_argument_of_str_must_be_list_or_dictionary), func_name); | 2780 semsg(_(e_argument_of_str_must_be_list_or_dictionary), func_name); |
2777 | |
2778 if (type != NULL) | |
2779 clear_type_list(&type_list); | |
2780 } | 2781 } |
2781 | 2782 |
2782 /* | 2783 /* |
2783 * "extend(list, list [, idx])" function | 2784 * "extend(list, list [, idx])" function |
2784 * "extend(dict, dict [, action])" function | 2785 * "extend(dict, dict [, action])" function |