To: vim_dev@googlegroups.com Subject: Patch 8.2.3894 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3894 Problem: Vim9: no proper type check for first argument of call(). Solution: Add specific type check. Files: src/evalfunc.c, src/typval.c, src/proto/typval.pro, src/errors.h, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.3893/src/evalfunc.c 2021-12-24 20:47:34.744104247 +0000 --- src/evalfunc.c 2021-12-25 19:22:48.182034536 +0000 *************** *** 2858,2864 **** dict_T *selfdict = NULL; if (in_vim9script() ! && (check_for_list_arg(argvars, 1) == FAIL || check_for_opt_dict_arg(argvars, 2) == FAIL)) return; --- 2858,2865 ---- dict_T *selfdict = NULL; if (in_vim9script() ! && (check_for_string_or_func_arg(argvars, 0) == FAIL ! || check_for_list_arg(argvars, 1) == FAIL || check_for_opt_dict_arg(argvars, 2) == FAIL)) return; *** ../vim-8.2.3893/src/typval.c 2021-12-22 21:40:29.350644184 +0000 --- src/typval.c 2021-12-25 19:25:23.382001411 +0000 *************** *** 757,762 **** --- 757,779 ---- } /* + * Give an error and return FAIL unless "args[idx]" is a string + * or a function reference. + */ + int + check_for_string_or_func_arg(typval_T *args, int idx) + { + if (args[idx].v_type != VAR_PARTIAL + && args[idx].v_type != VAR_FUNC + && args[idx].v_type != VAR_STRING) + { + semsg(_(e_string_or_function_required_for_argument_nr), idx + 1); + return FAIL; + } + return OK; + } + + /* * Give an error and return FAIL unless "args[idx]" is a list or a blob. */ int *** ../vim-8.2.3893/src/proto/typval.pro 2021-12-19 12:32:54.066426460 +0000 --- src/proto/typval.pro 2021-12-25 19:24:25.186019010 +0000 *************** *** 40,45 **** --- 40,46 ---- int check_for_string_or_number_or_list_arg(typval_T *args, int idx); int check_for_opt_string_or_number_or_list_arg(typval_T *args, int idx); int check_for_string_or_list_or_dict_arg(typval_T *args, int idx); + int check_for_string_or_func_arg(typval_T *args, int idx); int check_for_list_or_blob_arg(typval_T *args, int idx); int check_for_list_or_dict_arg(typval_T *args, int idx); int check_for_list_or_dict_or_blob_arg(typval_T *args, int idx); *** ../vim-8.2.3893/src/errors.h 2021-12-24 19:54:49.212150260 +0000 --- src/errors.h 2021-12-25 19:25:41.625994765 +0000 *************** *** 852,854 **** --- 852,856 ---- INIT(= N_("E1254: Cannot use script variable in for loop")); EXTERN char e_cmd_mapping_must_end_with_cr[] INIT(= N_("E1255: mapping must end with ")); + EXTERN char e_string_or_function_required_for_argument_nr[] + INIT(= N_("E1256: String or function required for argument %d")); *** ../vim-8.2.3893/src/testdir/test_vim9_builtin.vim 2021-12-22 18:45:25.255852542 +0000 --- src/testdir/test_vim9_builtin.vim 2021-12-25 19:28:34.001909555 +0000 *************** *** 402,407 **** --- 402,410 ---- var l = [3, 2, 1] call('reverse', [l]) l->assert_equal([1, 2, 3]) + + CheckDefExecAndScriptFailure(['call(123, [2])'], 'E1256: String or function required for argument 1') + CheckDefExecAndScriptFailure(['call(true, [2])'], 'E1256: String or function required for argument 1') CheckDefAndScriptFailure(['call("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list but got number', 'E1211: List required for argument 2']) CheckDefAndScriptFailure(['call("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict but got list', 'E1206: Dictionary required for argument 3']) enddef *** ../vim-8.2.3893/src/version.c 2021-12-25 18:23:20.770696173 +0000 --- src/version.c 2021-12-25 19:19:43.402184208 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3894, /**/ -- hundred-and-one symptoms of being an internet addict: 104. When people ask about the Presidential Election you ask "Which country?" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///