Mercurial > vim
comparison src/evalfunc.c @ 22844:36fc73078bce v8.2.1969
patch 8.2.1969: Vim9: map() may change the list or dict item type
Commit: https://github.com/vim/vim/commit/ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 9 18:31:39 2020 +0100
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().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 09 Nov 2020 18:45:04 +0100 |
parents | f2fbbb72ff28 |
children | eea4e7b67f24 |
comparison
equal
deleted
inserted
replaced
22843:b80694c9bb40 | 22844:36fc73078bce |
---|---|
477 static type_T * | 477 static type_T * |
478 ret_job(int argcount UNUSED, type_T **argtypes UNUSED) | 478 ret_job(int argcount UNUSED, type_T **argtypes UNUSED) |
479 { | 479 { |
480 return &t_job; | 480 return &t_job; |
481 } | 481 } |
482 | |
483 static type_T * | 482 static type_T * |
484 ret_first_arg(int argcount, type_T **argtypes) | 483 ret_first_arg(int argcount, type_T **argtypes) |
485 { | 484 { |
486 if (argcount > 0) | 485 if (argcount > 0) |
487 return argtypes[0]; | 486 return argtypes[0]; |
488 return &t_void; | 487 return &t_void; |
488 } | |
489 // for map(): returns first argument but item type may differ | |
490 static type_T * | |
491 ret_first_cont(int argcount UNUSED, type_T **argtypes) | |
492 { | |
493 if (argtypes[0]->tt_type == VAR_LIST) | |
494 return &t_list_any; | |
495 if (argtypes[0]->tt_type == VAR_DICT) | |
496 return &t_dict_any; | |
497 if (argtypes[0]->tt_type == VAR_BLOB) | |
498 return argtypes[0]; | |
499 return &t_any; | |
489 } | 500 } |
490 | 501 |
491 /* | 502 /* |
492 * Used for getqflist(): returns list if there is no argument, dict if there is | 503 * Used for getqflist(): returns list if there is no argument, dict if there is |
493 * one. | 504 * one. |
1113 #else | 1124 #else |
1114 NULL | 1125 NULL |
1115 #endif | 1126 #endif |
1116 }, | 1127 }, |
1117 {"map", 2, 2, FEARG_1, NULL, | 1128 {"map", 2, 2, FEARG_1, NULL, |
1118 ret_any, f_map}, | 1129 ret_first_cont, f_map}, |
1119 {"maparg", 1, 4, FEARG_1, NULL, | 1130 {"maparg", 1, 4, FEARG_1, NULL, |
1120 ret_maparg, f_maparg}, | 1131 ret_maparg, f_maparg}, |
1121 {"mapcheck", 1, 3, FEARG_1, NULL, | 1132 {"mapcheck", 1, 3, FEARG_1, NULL, |
1122 ret_string, f_mapcheck}, | 1133 ret_string, f_mapcheck}, |
1134 {"mapnew", 2, 2, FEARG_1, NULL, | |
1135 ret_first_cont, f_mapnew}, | |
1123 {"mapset", 3, 3, FEARG_1, NULL, | 1136 {"mapset", 3, 3, FEARG_1, NULL, |
1124 ret_void, f_mapset}, | 1137 ret_void, f_mapset}, |
1125 {"match", 2, 4, FEARG_1, NULL, | 1138 {"match", 2, 4, FEARG_1, NULL, |
1126 ret_any, f_match}, | 1139 ret_any, f_match}, |
1127 {"matchadd", 2, 5, FEARG_1, NULL, | 1140 {"matchadd", 2, 5, FEARG_1, NULL, |