summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2021-06-22 19:52:27 +0200
committerBram Moolenaar <Bram@vim.org>2021-06-22 19:52:27 +0200
commit7237cab8f1d1a4391372cafdb57f2d97f3b32d05 (patch)
treec6c3457afcaf57ddefd032acd00497f957006564 /src/evalfunc.c
parent831bdf8622fdfce7f02d48f847005e3909a055a8 (diff)
patch 8.2.3036: Vim9: builtin function arguments not checked at compile timev8.2.3036
Problem: Vim9: builtin function arguments not checked at compile time. Solution: Add more argument type specs. Check arguments to test_setmouse() and test_gui_mouse_event(). (Yegappan Lakshmanan, closes #8425)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c132
1 files changed, 68 insertions, 64 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index f8af8ef812..21d28afec6 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -403,12 +403,16 @@ arg_extend3(type_T *type, argcontext_T *context)
* Lists of functions that check the argument types of a builtin function.
*/
argcheck_T arg1_string[] = {arg_string};
-argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool};
+argcheck_T arg1_number[] = {arg_number};
argcheck_T arg1_float_or_nr[] = {arg_float_or_nr};
+argcheck_T arg2_float_or_nr[] = {arg_float_or_nr, arg_float_or_nr};
+argcheck_T arg2_number[] = {arg_number, arg_number};
argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev};
argcheck_T arg2_execute[] = {arg_string_or_list, arg_string};
argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3};
argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, arg_extend3};
+argcheck_T arg3_string[] = {arg_string, arg_string, arg_string};
+argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool};
argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number};
/*
@@ -670,25 +674,25 @@ static funcentry_T global_functions[] =
{
{"abs", 1, 1, FEARG_1, arg1_float_or_nr,
ret_any, FLOAT_FUNC(f_abs)},
- {"acos", 1, 1, FEARG_1, NULL,
+ {"acos", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_acos)},
{"add", 2, 2, FEARG_1, NULL /* arg2_listblob_item */,
ret_first_arg, f_add},
- {"and", 2, 2, FEARG_1, NULL,
+ {"and", 2, 2, FEARG_1, arg2_number,
ret_number, f_and},
{"append", 2, 2, FEARG_2, NULL,
ret_number_bool, f_append},
{"appendbufline", 3, 3, FEARG_3, NULL,
ret_number_bool, f_appendbufline},
- {"argc", 0, 1, 0, NULL,
+ {"argc", 0, 1, 0, arg1_number,
ret_number, f_argc},
{"argidx", 0, 0, 0, NULL,
ret_number, f_argidx},
- {"arglistid", 0, 2, 0, NULL,
+ {"arglistid", 0, 2, 0, arg2_number,
ret_number, f_arglistid},
- {"argv", 0, 2, 0, NULL,
+ {"argv", 0, 2, 0, arg2_number,
ret_argv, f_argv},
- {"asin", 1, 1, FEARG_1, NULL,
+ {"asin", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_asin)},
{"assert_beeps", 1, 2, FEARG_1, NULL,
ret_number_bool, f_assert_beeps},
@@ -716,9 +720,9 @@ static funcentry_T global_functions[] =
ret_number_bool, f_assert_report},
{"assert_true", 1, 2, FEARG_1, NULL,
ret_number_bool, f_assert_true},
- {"atan", 1, 1, FEARG_1, NULL,
+ {"atan", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_atan)},
- {"atan2", 2, 2, FEARG_1, NULL,
+ {"atan2", 2, 2, FEARG_1, arg2_float_or_nr,
ret_float, FLOAT_FUNC(f_atan2)},
{"balloon_gettext", 0, 0, 0, NULL,
ret_string,
@@ -780,7 +784,7 @@ static funcentry_T global_functions[] =
ret_number, f_byteidxcomp},
{"call", 2, 3, FEARG_1, NULL,
ret_any, f_call},
- {"ceil", 1, 1, FEARG_1, NULL,
+ {"ceil", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_ceil)},
{"ch_canread", 1, 1, FEARG_1, NULL,
ret_number_bool, JOB_FUNC(f_ch_canread)},
@@ -832,7 +836,7 @@ static funcentry_T global_functions[] =
ret_string, f_chdir},
{"cindent", 1, 1, FEARG_1, NULL,
ret_number, f_cindent},
- {"clearmatches", 0, 1, FEARG_1, NULL,
+ {"clearmatches", 0, 1, FEARG_1, arg1_number,
ret_void, f_clearmatches},
{"col", 1, 1, FEARG_1, NULL,
ret_number, f_col},
@@ -848,9 +852,9 @@ static funcentry_T global_functions[] =
ret_number, f_confirm},
{"copy", 1, 1, FEARG_1, NULL,
ret_first_arg, f_copy},
- {"cos", 1, 1, FEARG_1, NULL,
+ {"cos", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_cos)},
- {"cosh", 1, 1, FEARG_1, NULL,
+ {"cosh", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_cosh)},
{"count", 2, 4, FEARG_1, NULL,
ret_number, f_count},
@@ -858,7 +862,7 @@ static funcentry_T global_functions[] =
ret_number, f_cscope_connection},
{"cursor", 1, 3, FEARG_1, NULL,
ret_number, f_cursor},
- {"debugbreak", 1, 1, FEARG_1, NULL,
+ {"debugbreak", 1, 1, FEARG_1, arg1_number,
ret_number,
#ifdef MSWIN
f_debugbreak
@@ -898,7 +902,7 @@ static funcentry_T global_functions[] =
ret_string, f_exepath},
{"exists", 1, 1, FEARG_1, NULL,
ret_number_bool, f_exists},
- {"exp", 1, 1, FEARG_1, NULL,
+ {"exp", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_exp)},
{"expand", 1, 3, FEARG_1, NULL,
ret_any, f_expand},
@@ -926,11 +930,11 @@ static funcentry_T global_functions[] =
ret_list_any, f_flatten},
{"flattennew", 1, 2, FEARG_1, NULL,
ret_list_any, f_flattennew},
- {"float2nr", 1, 1, FEARG_1, NULL,
+ {"float2nr", 1, 1, FEARG_1, arg1_float_or_nr,
ret_number, FLOAT_FUNC(f_float2nr)},
- {"floor", 1, 1, FEARG_1, NULL,
+ {"floor", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_floor)},
- {"fmod", 2, 2, FEARG_1, NULL,
+ {"fmod", 2, 2, FEARG_1, arg2_float_or_nr,
ret_float, FLOAT_FUNC(f_fmod)},
{"fnameescape", 1, 1, FEARG_1, NULL,
ret_string, f_fnameescape},
@@ -986,11 +990,11 @@ static funcentry_T global_functions[] =
ret_string, f_getcmdwintype},
{"getcompletion", 2, 3, FEARG_1, NULL,
ret_list_string, f_getcompletion},
- {"getcurpos", 0, 1, FEARG_1, NULL,
+ {"getcurpos", 0, 1, FEARG_1, arg1_number,
ret_list_number, f_getcurpos},
- {"getcursorcharpos", 0, 1, FEARG_1, NULL,
+ {"getcursorcharpos", 0, 1, FEARG_1, arg1_number,
ret_list_number, f_getcursorcharpos},
- {"getcwd", 0, 2, FEARG_1, NULL,
+ {"getcwd", 0, 2, FEARG_1, arg2_number,
ret_string, f_getcwd},
{"getenv", 1, 1, FEARG_1, NULL,
ret_any, f_getenv},
@@ -1006,7 +1010,7 @@ static funcentry_T global_functions[] =
ret_string, f_getftype},
{"getimstatus", 0, 0, 0, NULL,
ret_number_bool, f_getimstatus},
- {"getjumplist", 0, 2, FEARG_1, NULL,
+ {"getjumplist", 0, 2, FEARG_1, arg2_number,
ret_list_any, f_getjumplist},
{"getline", 1, 2, FEARG_1, NULL,
ret_f_getline, f_getline},
@@ -1014,7 +1018,7 @@ static funcentry_T global_functions[] =
ret_list_or_dict_1, f_getloclist},
{"getmarklist", 0, 1, FEARG_1, NULL,
ret_list_dict_any, f_getmarklist},
- {"getmatches", 0, 1, 0, NULL,
+ {"getmatches", 0, 1, 0, arg1_number,
ret_list_dict_any, f_getmatches},
{"getmousepos", 0, 0, 0, NULL,
ret_dict_number, f_getmousepos},
@@ -1030,19 +1034,19 @@ static funcentry_T global_functions[] =
ret_dict_any, f_getreginfo},
{"getregtype", 0, 1, FEARG_1, NULL,
ret_string, f_getregtype},
- {"gettabinfo", 0, 1, FEARG_1, NULL,
+ {"gettabinfo", 0, 1, FEARG_1, arg1_number,
ret_list_dict_any, f_gettabinfo},
{"gettabvar", 2, 3, FEARG_1, NULL,
ret_any, f_gettabvar},
{"gettabwinvar", 3, 4, FEARG_1, NULL,
ret_any, f_gettabwinvar},
- {"gettagstack", 0, 1, FEARG_1, NULL,
+ {"gettagstack", 0, 1, FEARG_1, arg1_number,
ret_dict_any, f_gettagstack},
{"gettext", 1, 1, FEARG_1, NULL,
ret_string, f_gettext},
- {"getwininfo", 0, 1, FEARG_1, NULL,
+ {"getwininfo", 0, 1, FEARG_1, arg1_number,
ret_list_dict_any, f_getwininfo},
- {"getwinpos", 0, 1, FEARG_1, NULL,
+ {"getwinpos", 0, 1, FEARG_1, arg1_number,
ret_list_number, f_getwinpos},
{"getwinposx", 0, 0, 0, NULL,
ret_number, f_getwinposx},
@@ -1060,7 +1064,7 @@ static funcentry_T global_functions[] =
ret_number_bool, f_has},
{"has_key", 2, 2, FEARG_1, NULL,
ret_number_bool, f_has_key},
- {"haslocaldir", 0, 2, FEARG_1, NULL,
+ {"haslocaldir", 0, 2, FEARG_1, arg2_number,
ret_number, f_haslocaldir},
{"hasmapto", 1, 3, FEARG_1, NULL,
ret_number_bool, f_hasmapto},
@@ -1104,15 +1108,15 @@ static funcentry_T global_functions[] =
ret_first_arg, f_insert},
{"interrupt", 0, 0, 0, NULL,
ret_void, f_interrupt},
- {"invert", 1, 1, FEARG_1, NULL,
+ {"invert", 1, 1, FEARG_1, arg1_number,
ret_number, f_invert},
{"isdirectory", 1, 1, FEARG_1, NULL,
ret_number_bool, f_isdirectory},
- {"isinf", 1, 1, FEARG_1, NULL,
+ {"isinf", 1, 1, FEARG_1, arg1_float_or_nr,
ret_number, MATH_FUNC(f_isinf)},
{"islocked", 1, 1, FEARG_1, NULL,
ret_number_bool, f_islocked},
- {"isnan", 1, 1, FEARG_1, NULL,
+ {"isnan", 1, 1, FEARG_1, arg1_float_or_nr,
ret_number_bool, MATH_FUNC(f_isnan)},
{"items", 1, 1, FEARG_1, NULL,
ret_list_any, f_items},
@@ -1160,13 +1164,13 @@ static funcentry_T global_functions[] =
ret_number, f_listener_add},
{"listener_flush", 0, 1, FEARG_1, NULL,
ret_void, f_listener_flush},
- {"listener_remove", 1, 1, FEARG_1, NULL,
+ {"listener_remove", 1, 1, FEARG_1, arg1_number,
ret_number_bool, f_listener_remove},
{"localtime", 0, 0, 0, NULL,
ret_number, f_localtime},
- {"log", 1, 1, FEARG_1, NULL,
+ {"log", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_log)},
- {"log10", 1, 1, FEARG_1, NULL,
+ {"log10", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_log10)},
{"luaeval", 1, 2, FEARG_1, NULL,
ret_any,
@@ -1192,9 +1196,9 @@ static funcentry_T global_functions[] =
ret_number, f_matchadd},
{"matchaddpos", 2, 5, FEARG_1, NULL,
ret_number, f_matchaddpos},
- {"matcharg", 1, 1, FEARG_1, NULL,
+ {"matcharg", 1, 1, FEARG_1, arg1_number,
ret_list_string, f_matcharg},
- {"matchdelete", 1, 2, FEARG_1, NULL,
+ {"matchdelete", 1, 2, FEARG_1, arg2_number,
ret_number_bool, f_matchdelete},
{"matchend", 2, 4, FEARG_1, NULL,
ret_number, f_matchend},
@@ -1236,7 +1240,7 @@ static funcentry_T global_functions[] =
ret_number, f_nextnonblank},
{"nr2char", 1, 2, FEARG_1, NULL,
ret_string, f_nr2char},
- {"or", 2, 2, FEARG_1, NULL,
+ {"or", 2, 2, FEARG_1, arg2_number,
ret_number, f_or},
{"pathshorten", 1, 2, FEARG_1, NULL,
ret_string, f_pathshorten},
@@ -1290,7 +1294,7 @@ static funcentry_T global_functions[] =
ret_void, PROP_FUNC(f_popup_settext)},
{"popup_show", 1, 1, FEARG_1, NULL,
ret_void, PROP_FUNC(f_popup_show)},
- {"pow", 2, 2, FEARG_1, NULL,
+ {"pow", 2, 2, FEARG_1, arg2_float_or_nr,
ret_float, FLOAT_FUNC(f_pow)},
{"prevnonblank", 1, 1, FEARG_1, NULL,
ret_number, f_prevnonblank},
@@ -1398,7 +1402,7 @@ static funcentry_T global_functions[] =
ret_string, f_resolve},
{"reverse", 1, 1, FEARG_1, NULL,
ret_first_arg, f_reverse},
- {"round", 1, 1, FEARG_1, NULL,
+ {"round", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_round)},
{"rubyeval", 1, 1, FEARG_1, NULL,
ret_any,
@@ -1408,11 +1412,11 @@ static funcentry_T global_functions[] =
NULL
#endif
},
- {"screenattr", 2, 2, FEARG_1, NULL,
+ {"screenattr", 2, 2, FEARG_1, arg2_number,
ret_number, f_screenattr},
- {"screenchar", 2, 2, FEARG_1, NULL,
+ {"screenchar", 2, 2, FEARG_1, arg2_number,
ret_number, f_screenchar},
- {"screenchars", 2, 2, FEARG_1, NULL,
+ {"screenchars", 2, 2, FEARG_1, arg2_number,
ret_list_number, f_screenchars},
{"screencol", 0, 0, 0, NULL,
ret_number, f_screencol},
@@ -1420,7 +1424,7 @@ static funcentry_T global_functions[] =
ret_dict_number, f_screenpos},
{"screenrow", 0, 0, 0, NULL,
ret_number, f_screenrow},
- {"screenstring", 2, 2, FEARG_1, NULL,
+ {"screenstring", 2, 2, FEARG_1, arg2_number,
ret_string, f_screenstring},
{"search", 1, 5, FEARG_1, NULL,
ret_number, f_search},
@@ -1448,7 +1452,7 @@ static funcentry_T global_functions[] =
ret_number_bool, f_setcharpos},
{"setcharsearch", 1, 1, FEARG_1, NULL,
ret_void, f_setcharsearch},
- {"setcmdpos", 1, 1, FEARG_1, NULL,
+ {"setcmdpos", 1, 1, FEARG_1, arg1_number,
ret_number_bool, f_setcmdpos},
{"setcursorcharpos", 1, 3, FEARG_1, NULL,
ret_number_bool, f_setcursorcharpos},
@@ -1486,7 +1490,7 @@ static funcentry_T global_functions[] =
},
{"shellescape", 1, 2, FEARG_1, NULL,
ret_string, f_shellescape},
- {"shiftwidth", 0, 1, FEARG_1, NULL,
+ {"shiftwidth", 0, 1, FEARG_1, arg1_number,
ret_number, f_shiftwidth},
{"sign_define", 1, 2, FEARG_1, NULL,
ret_any, SIGN_FUNC(f_sign_define)},
@@ -1508,9 +1512,9 @@ static funcentry_T global_functions[] =
ret_list_number, SIGN_FUNC(f_sign_unplacelist)},
{"simplify", 1, 1, FEARG_1, NULL,
ret_string, f_simplify},
- {"sin", 1, 1, FEARG_1, NULL,
+ {"sin", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_sin)},
- {"sinh", 1, 1, FEARG_1, NULL,
+ {"sinh", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_sinh)},
{"slice", 2, 3, FEARG_1, NULL,
ret_first_arg, f_slice},
@@ -1532,7 +1536,7 @@ static funcentry_T global_functions[] =
ret_list_string, f_spellsuggest},
{"split", 1, 3, FEARG_1, NULL,
ret_list_string, f_split},
- {"sqrt", 1, 1, FEARG_1, NULL,
+ {"sqrt", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_sqrt)},
{"srand", 0, 1, FEARG_1, NULL,
ret_list_number, f_srand},
@@ -1616,9 +1620,9 @@ static funcentry_T global_functions[] =
ret_list_string, f_tagfiles},
{"taglist", 1, 2, FEARG_1, NULL,
ret_list_dict_any, f_taglist},
- {"tan", 1, 1, FEARG_1, NULL,
+ {"tan", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_tan)},
- {"tanh", 1, 1, FEARG_1, NULL,
+ {"tanh", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_tanh)},
{"tempname", 0, 0, 0, NULL,
ret_string, f_tempname},
@@ -1750,15 +1754,15 @@ static funcentry_T global_functions[] =
ret_void, TIMER_FUNC(f_timer_stop)},
{"timer_stopall", 0, 0, 0, NULL,
ret_void, TIMER_FUNC(f_timer_stopall)},
- {"tolower", 1, 1, FEARG_1, NULL,
+ {"tolower", 1, 1, FEARG_1, arg1_string,
ret_string, f_tolower},
- {"toupper", 1, 1, FEARG_1, NULL,
+ {"toupper", 1, 1, FEARG_1, arg1_string,
ret_string, f_toupper},
- {"tr", 3, 3, FEARG_1, NULL,
+ {"tr", 3, 3, FEARG_1, arg3_string,
ret_string, f_tr},
{"trim", 1, 3, FEARG_1, NULL,
ret_string, f_trim},
- {"trunc", 1, 1, FEARG_1, NULL,
+ {"trunc", 1, 1, FEARG_1, arg1_float_or_nr,
ret_float, FLOAT_FUNC(f_trunc)},
{"type", 1, 1, FEARG_1, NULL,
ret_number, f_type},
@@ -1784,27 +1788,27 @@ static funcentry_T global_functions[] =
ret_list_number, f_win_findbuf},
{"win_getid", 0, 2, FEARG_1, NULL,
ret_number, f_win_getid},
- {"win_gettype", 0, 1, FEARG_1, NULL,
+ {"win_gettype", 0, 1, FEARG_1, arg1_number,
ret_string, f_win_gettype},
- {"win_gotoid", 1, 1, FEARG_1, NULL,
+ {"win_gotoid", 1, 1, FEARG_1, arg1_number,
ret_number_bool, f_win_gotoid},
- {"win_id2tabwin", 1, 1, FEARG_1, NULL,
+ {"win_id2tabwin", 1, 1, FEARG_1, arg1_number,
ret_list_number, f_win_id2tabwin},
- {"win_id2win", 1, 1, FEARG_1, NULL,
+ {"win_id2win", 1, 1, FEARG_1, arg1_number,
ret_number, f_win_id2win},
- {"win_screenpos", 1, 1, FEARG_1, NULL,
+ {"win_screenpos", 1, 1, FEARG_1, arg1_number,
ret_list_number, f_win_screenpos},
{"win_splitmove", 2, 3, FEARG_1, NULL,
ret_number_bool, f_win_splitmove},
- {"winbufnr", 1, 1, FEARG_1, NULL,
+ {"winbufnr", 1, 1, FEARG_1, arg1_number,
ret_number, f_winbufnr},
{"wincol", 0, 0, 0, NULL,
ret_number, f_wincol},
{"windowsversion", 0, 0, 0, NULL,
ret_string, f_windowsversion},
- {"winheight", 1, 1, FEARG_1, NULL,
+ {"winheight", 1, 1, FEARG_1, arg1_number,
ret_number, f_winheight},
- {"winlayout", 0, 1, FEARG_1, NULL,
+ {"winlayout", 0, 1, FEARG_1, arg1_number,
ret_list_any, f_winlayout},
{"winline", 0, 0, 0, NULL,
ret_number, f_winline},
@@ -1816,13 +1820,13 @@ static funcentry_T global_functions[] =
ret_void, f_winrestview},
{"winsaveview", 0, 0, 0, NULL,
ret_dict_number, f_winsaveview},
- {"winwidth", 1, 1, FEARG_1, NULL,
+ {"winwidth", 1, 1, FEARG_1, arg1_number,
ret_number, f_winwidth},
{"wordcount", 0, 0, 0, NULL,
ret_dict_number, f_wordcount},
{"writefile", 2, 3, FEARG_1, NULL,
ret_number_bool, f_writefile},
- {"xor", 2, 2, FEARG_1, NULL,
+ {"xor", 2, 2, FEARG_1, arg2_number,
ret_number, f_xor},
};