diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-02-22 21:54:44 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-02-22 21:54:44 +0000 |
commit | e843efcc3503b7af838dca3cb9dd2e17d4fc1672 (patch) | |
tree | c4734aed2a84229f73f5be166da42d802bbae625 /src/evalfunc.c | |
parent | b2c72359dce4c4027dc0c05844eb2e76ea947014 (diff) |
patch 8.2.4449: vim9: function argument of sort() not checked at compile timev8.2.4449
Problem: vim9: function argument of sort() not checked at compile time.
Solution: Add a compile time check.
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r-- | src/evalfunc.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 69b4a23ac6..cea002f11c 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -596,6 +596,43 @@ arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) } /* + * Check second argument of sort() and uniq(), the "how" argument. + */ + static int +arg_sort_how(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) +{ + if (type->tt_type == VAR_STRING + || type->tt_type == VAR_PARTIAL + || type == &t_unknown + || type == &t_any) + return OK; + + if (type->tt_type == VAR_FUNC) + { + type_T *(args[2]); + type_T t_func_exp = {VAR_FUNC, 2, 0, 0, &t_number, args}; + + if (context->arg_types[0].type_curr->tt_type == VAR_LIST) + args[0] = context->arg_types[0].type_curr->tt_member; + else + args[0] = &t_unknown; + if ((type->tt_member != &t_any && type->tt_member != &t_unknown) + || args[0] != &t_unknown) + { + where_T where = WHERE_INIT; + + args[1] = args[0]; + where.wt_index = 2; + return check_type(&t_func_exp, type, TRUE, where); + } + + return OK; + } + semsg(_(e_string_or_function_required_for_argument_nr), 2); + return FAIL; +} + +/* * Check an expression argument, can be a string, funcref or partial. * Also accept a bool, a constant resulting from compiling a string argument. * Also accept a number, one and zero are accepted. @@ -1006,7 +1043,7 @@ static argcheck_T arg23_settagstack[] = {arg_number, arg_dict_any, arg_string}; static argcheck_T arg02_sign_getplaced[] = {arg_buffer, arg_dict_any}; static argcheck_T arg45_sign_place[] = {arg_number, arg_string, arg_string, arg_buffer, arg_dict_any}; static argcheck_T arg23_slice[] = {arg_slice1, arg_number, arg_number}; -static argcheck_T arg13_sortuniq[] = {arg_list_any, NULL, arg_dict_any}; +static argcheck_T arg13_sortuniq[] = {arg_list_any, arg_sort_how, arg_dict_any}; static argcheck_T arg24_strpart[] = {arg_string, arg_number, arg_number, arg_bool}; static argcheck_T arg12_system[] = {arg_string, arg_str_or_nr_or_list}; static argcheck_T arg23_win_execute[] = {arg_number, arg_string_or_list_string, arg_string}; |