comparison src/evalfunc.c @ 24972:b11f38f77006 v8.2.3023

patch 8.2.3023: Vim9: arguments for execute() not checked at compile time Commit: https://github.com/vim/vim/commit/ca81f0e834640cf3465b3b742e60c12e8a0956f2 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 20 14:41:01 2021 +0200 patch 8.2.3023: Vim9: arguments for execute() not checked at compile time Problem: Vim9: arguments for execute() not checked at compile time. Solution: Add a function to check the argument types.
author Bram Moolenaar <Bram@vim.org>
date Sun, 20 Jun 2021 14:45:03 +0200
parents 7e9e53a0368f
children 4cb423b9250d
comparison
equal deleted inserted replaced
24971:f06b8d3bda25 24972:b11f38f77006
300 arg_type_mismatch(&t_list_any, type, context->arg_idx + 1); 300 arg_type_mismatch(&t_list_any, type, context->arg_idx + 1);
301 return FAIL; 301 return FAIL;
302 } 302 }
303 303
304 /* 304 /*
305 * Check "type" is a string or a list of strings.
306 */
307 static int
308 arg_string_or_list(type_T *type, argcontext_T *context)
309 {
310 if (type->tt_type == VAR_ANY || type->tt_type == VAR_STRING)
311 return OK;
312 if (type->tt_type != VAR_LIST)
313 {
314 arg_type_mismatch(&t_string, type, context->arg_idx + 1);
315 return FAIL;
316 }
317 if (type->tt_member->tt_type == VAR_ANY
318 || type->tt_member->tt_type == VAR_STRING)
319 return OK;
320
321 arg_type_mismatch(&t_list_string, type, context->arg_idx + 1);
322 return FAIL;
323 }
324
325 /*
305 * Check "type" is a list or a dict. 326 * Check "type" is a list or a dict.
306 */ 327 */
307 static int 328 static int
308 arg_list_or_dict(type_T *type, argcontext_T *context) 329 arg_list_or_dict(type_T *type, argcontext_T *context)
309 { 330 {
383 */ 404 */
384 argcheck_T arg1_string[] = {arg_string}; 405 argcheck_T arg1_string[] = {arg_string};
385 argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool}; 406 argcheck_T arg3_string_nr_bool[] = {arg_string, arg_number, arg_bool};
386 argcheck_T arg1_float_or_nr[] = {arg_float_or_nr}; 407 argcheck_T arg1_float_or_nr[] = {arg_float_or_nr};
387 argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev}; 408 argcheck_T arg2_listblob_item[] = {arg_list_or_blob, arg_item_of_prev};
409 argcheck_T arg2_execute[] = {arg_string_or_list, arg_string};
388 argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3}; 410 argcheck_T arg23_extend[] = {arg_list_or_dict, arg_same_as_prev, arg_extend3};
389 argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, arg_extend3}; 411 argcheck_T arg23_extendnew[] = {arg_list_or_dict, arg_same_struct_as_prev, arg_extend3};
390 argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number}; 412 argcheck_T arg3_insert[] = {arg_list_or_blob, arg_item_of_prev, arg_number};
391 413
392 /* 414 /*
868 ret_any, f_eval}, 890 ret_any, f_eval},
869 {"eventhandler", 0, 0, 0, NULL, 891 {"eventhandler", 0, 0, 0, NULL,
870 ret_number_bool, f_eventhandler}, 892 ret_number_bool, f_eventhandler},
871 {"executable", 1, 1, FEARG_1, NULL, 893 {"executable", 1, 1, FEARG_1, NULL,
872 ret_number, f_executable}, 894 ret_number, f_executable},
873 {"execute", 1, 2, FEARG_1, NULL, 895 {"execute", 1, 2, FEARG_1, arg2_execute,
874 ret_string, f_execute}, 896 ret_string, f_execute},
875 {"exepath", 1, 1, FEARG_1, NULL, 897 {"exepath", 1, 1, FEARG_1, NULL,
876 ret_string, f_exepath}, 898 ret_string, f_exepath},
877 {"exists", 1, 1, FEARG_1, NULL, 899 {"exists", 1, 1, FEARG_1, NULL,
878 ret_number_bool, f_exists}, 900 ret_number_bool, f_exists},