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().
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 6a43120..b5f1c00 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -479,7 +479,6 @@
{
return &t_job;
}
-
static type_T *
ret_first_arg(int argcount, type_T **argtypes)
{
@@ -487,6 +486,18 @@
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 @@
#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,