Mercurial > vim
comparison src/evalfunc.c @ 31742:f578bef02249 v9.0.1203
patch 9.0.1203: return type of values() is always list<any>
Commit: https://github.com/vim/vim/commit/32517c4c14ed3f9240fcd5b7c01d0ca2e586f7e4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 15 18:17:12 2023 +0000
patch 9.0.1203: return type of values() is always list<any>
Problem: Return type of values() is always list<any>.
Solution: Use the member type if possible. (issue https://github.com/vim/vim/issues/11822)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 15 Jan 2023 19:30:04 +0100 |
parents | b89cfd86e18e |
children | f348559ce426 |
comparison
equal
deleted
inserted
replaced
31741:47e20df6fce5 | 31742:f578bef02249 |
---|---|
1134 static argcheck_T arg12_system[] = {arg_string, arg_str_or_nr_or_list}; | 1134 static argcheck_T arg12_system[] = {arg_string, arg_str_or_nr_or_list}; |
1135 static argcheck_T arg23_win_execute[] = {arg_number, arg_string_or_list_string, arg_string}; | 1135 static argcheck_T arg23_win_execute[] = {arg_number, arg_string_or_list_string, arg_string}; |
1136 static argcheck_T arg23_writefile[] = {arg_list_or_blob, arg_string, arg_string}; | 1136 static argcheck_T arg23_writefile[] = {arg_list_or_blob, arg_string, arg_string}; |
1137 static argcheck_T arg24_match_func[] = {arg_string_or_list_any, arg_string, arg_number, arg_number}; | 1137 static argcheck_T arg24_match_func[] = {arg_string_or_list_any, arg_string, arg_number, arg_number}; |
1138 | 1138 |
1139 // Can be used by functions called through "f_retfunc" to create new types. | |
1140 static garray_T *current_type_gap = NULL; | |
1139 | 1141 |
1140 /* | 1142 /* |
1141 * Functions that return the return type of a builtin function. | 1143 * Functions that return the return type of a builtin function. |
1142 * Note that "argtypes" is NULL if "argcount" is zero. | 1144 * Note that "argtypes" is NULL if "argcount" is zero. |
1143 */ | 1145 */ |
1435 { | 1437 { |
1436 if (argcount < 3) | 1438 if (argcount < 3) |
1437 return &t_string; | 1439 return &t_string; |
1438 // Depending on the count would be a string or a list of strings. | 1440 // Depending on the count would be a string or a list of strings. |
1439 return &t_any; | 1441 return &t_any; |
1442 } | |
1443 // for values(): list of member of first argument | |
1444 static type_T * | |
1445 ret_list_member(int argcount, | |
1446 type2_T *argtypes, | |
1447 type_T **decl_type) | |
1448 { | |
1449 if (argcount > 0) | |
1450 { | |
1451 type_T *t = argtypes[0].type_decl; | |
1452 if (current_type_gap != NULL | |
1453 && (t->tt_type == VAR_DICT || t->tt_type == VAR_LIST)) | |
1454 t = get_list_type(t->tt_member, current_type_gap); | |
1455 else | |
1456 t = &t_list_any; | |
1457 *decl_type = t; | |
1458 | |
1459 t = argtypes[0].type_curr; | |
1460 if (current_type_gap != NULL | |
1461 && (t->tt_type == VAR_DICT || t->tt_type == VAR_LIST)) | |
1462 return get_list_type(t->tt_member, current_type_gap); | |
1463 } | |
1464 return &t_list_any; | |
1440 } | 1465 } |
1441 | 1466 |
1442 /* | 1467 /* |
1443 * Used for getqflist(): returns list if there is no argument, dict if there is | 1468 * Used for getqflist(): returns list if there is no argument, dict if there is |
1444 * one. | 1469 * one. |
2757 {"undotree", 0, 0, 0, NULL, | 2782 {"undotree", 0, 0, 0, NULL, |
2758 ret_dict_any, f_undotree}, | 2783 ret_dict_any, f_undotree}, |
2759 {"uniq", 1, 3, FEARG_1, arg13_sortuniq, | 2784 {"uniq", 1, 3, FEARG_1, arg13_sortuniq, |
2760 ret_first_arg, f_uniq}, | 2785 ret_first_arg, f_uniq}, |
2761 {"values", 1, 1, FEARG_1, arg1_dict_any, | 2786 {"values", 1, 1, FEARG_1, arg1_dict_any, |
2762 ret_list_any, f_values}, | 2787 ret_list_member, f_values}, |
2763 {"virtcol", 1, 2, FEARG_1, arg2_string_or_list_bool, | 2788 {"virtcol", 1, 2, FEARG_1, arg2_string_or_list_bool, |
2764 ret_virtcol, f_virtcol}, | 2789 ret_virtcol, f_virtcol}, |
2765 {"virtcol2col", 3, 3, FEARG_1, arg3_number, | 2790 {"virtcol2col", 3, 3, FEARG_1, arg3_number, |
2766 ret_number, f_virtcol2col}, | 2791 ret_number, f_virtcol2col}, |
2767 {"visualmode", 0, 1, 0, arg1_bool, | 2792 {"visualmode", 0, 1, 0, arg1_bool, |
2991 type_T * | 3016 type_T * |
2992 internal_func_ret_type( | 3017 internal_func_ret_type( |
2993 int idx, | 3018 int idx, |
2994 int argcount, | 3019 int argcount, |
2995 type2_T *argtypes, | 3020 type2_T *argtypes, |
2996 type_T **decl_type) | 3021 type_T **decl_type, |
3022 garray_T *type_gap) | |
2997 { | 3023 { |
2998 type_T *ret; | 3024 type_T *ret; |
2999 | 3025 |
3026 current_type_gap = type_gap; | |
3000 *decl_type = NULL; | 3027 *decl_type = NULL; |
3001 ret = global_functions[idx].f_retfunc(argcount, argtypes, decl_type); | 3028 ret = global_functions[idx].f_retfunc(argcount, argtypes, decl_type); |
3002 if (*decl_type == NULL) | 3029 if (*decl_type == NULL) |
3003 *decl_type = ret; | 3030 *decl_type = ret; |
3031 current_type_gap = NULL; | |
3004 return ret; | 3032 return ret; |
3005 } | 3033 } |
3006 | 3034 |
3007 /* | 3035 /* |
3008 * Return TRUE if "idx" is for the map() function. | 3036 * Return TRUE if "idx" is for the map() function. |