0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 8.2.1969: Vim9: map() may change the list or dict item type

Problem:    Vim9: map() may change the list or dict item type.
Solution:   Add mapnew().
This commit is contained in:
Bram Moolenaar
2020-11-09 18:31:39 +01:00
parent 8cebd43e97
commit ea696852e7
7 changed files with 205 additions and 53 deletions

View File

@@ -479,7 +479,6 @@ ret_job(int argcount UNUSED, type_T **argtypes UNUSED)
{
return &t_job;
}
static type_T *
ret_first_arg(int argcount, type_T **argtypes)
{
@@ -487,6 +486,18 @@ ret_first_arg(int argcount, type_T **argtypes)
return argtypes[0];
return &t_void;
}
// for map(): returns first argument but item type may differ
static type_T *
ret_first_cont(int argcount UNUSED, type_T **argtypes)
{
if (argtypes[0]->tt_type == VAR_LIST)
return &t_list_any;
if (argtypes[0]->tt_type == VAR_DICT)
return &t_dict_any;
if (argtypes[0]->tt_type == VAR_BLOB)
return argtypes[0];
return &t_any;
}
/*
* Used for getqflist(): returns list if there is no argument, dict if there is
@@ -1115,11 +1126,13 @@ static funcentry_T global_functions[] =
#endif
},
{"map", 2, 2, FEARG_1, NULL,
ret_any, f_map},
ret_first_cont, f_map},
{"maparg", 1, 4, FEARG_1, NULL,
ret_maparg, f_maparg},
{"mapcheck", 1, 3, FEARG_1, NULL,
ret_string, f_mapcheck},
{"mapnew", 2, 2, FEARG_1, NULL,
ret_first_cont, f_mapnew},
{"mapset", 3, 3, FEARG_1, NULL,
ret_void, f_mapset},
{"match", 2, 4, FEARG_1, NULL,