summaryrefslogtreecommitdiff
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-11-09 18:31:39 +0100
committerBram Moolenaar <Bram@vim.org>2020-11-09 18:31:39 +0100
commitea696852e7abcdebaf7f17a7f23dc90df1f5e2ed (patch)
treeeedb0a14d24d7ec03f0caa021a1aafea78a1d83b /src/evalfunc.c
parent8cebd43e9774d2624af43ee5b86939886f2ba490 (diff)
downloadvim-git-ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed.tar.gz
patch 8.2.1969: Vim9: map() may change the list or dict item typev8.2.1969
Problem: Vim9: map() may change the list or dict item type. Solution: Add mapnew().
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 6a43120d4..b5f1c0051 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -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,