forked from aniani/vim
patch 8.2.3894: Vim9: no proper type check for first argument of call()
Problem: Vim9: no proper type check for first argument of call(). Solution: Add specific type check.
This commit is contained in:
parent
5cd647935d
commit
223d0a6bc8
@ -852,3 +852,5 @@ EXTERN char e_cannot_use_script_variable_in_for_loop[]
|
|||||||
INIT(= N_("E1254: Cannot use script variable in for loop"));
|
INIT(= N_("E1254: Cannot use script variable in for loop"));
|
||||||
EXTERN char e_cmd_mapping_must_end_with_cr[]
|
EXTERN char e_cmd_mapping_must_end_with_cr[]
|
||||||
INIT(= N_("E1255: <Cmd> mapping must end with <CR>"));
|
INIT(= N_("E1255: <Cmd> mapping must end with <CR>"));
|
||||||
|
EXTERN char e_string_or_function_required_for_argument_nr[]
|
||||||
|
INIT(= N_("E1256: String or function required for argument %d"));
|
||||||
|
@ -2858,7 +2858,8 @@ f_call(typval_T *argvars, typval_T *rettv)
|
|||||||
dict_T *selfdict = NULL;
|
dict_T *selfdict = NULL;
|
||||||
|
|
||||||
if (in_vim9script()
|
if (in_vim9script()
|
||||||
&& (check_for_list_arg(argvars, 1) == FAIL
|
&& (check_for_string_or_func_arg(argvars, 0) == FAIL
|
||||||
|
|| check_for_list_arg(argvars, 1) == FAIL
|
||||||
|| check_for_opt_dict_arg(argvars, 2) == FAIL))
|
|| check_for_opt_dict_arg(argvars, 2) == FAIL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ int check_for_string_or_dict_arg(typval_T *args, int idx);
|
|||||||
int check_for_string_or_number_or_list_arg(typval_T *args, int idx);
|
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_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_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_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_arg(typval_T *args, int idx);
|
||||||
int check_for_list_or_dict_or_blob_arg(typval_T *args, int idx);
|
int check_for_list_or_dict_or_blob_arg(typval_T *args, int idx);
|
||||||
|
@ -402,6 +402,9 @@ def Test_call_call()
|
|||||||
var l = [3, 2, 1]
|
var l = [3, 2, 1]
|
||||||
call('reverse', [l])
|
call('reverse', [l])
|
||||||
l->assert_equal([1, 2, 3])
|
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<any> but got number', 'E1211: List required for argument 2'])
|
CheckDefAndScriptFailure(['call("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
|
||||||
CheckDefAndScriptFailure(['call("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
|
CheckDefAndScriptFailure(['call("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
|
||||||
enddef
|
enddef
|
||||||
|
17
src/typval.c
17
src/typval.c
@ -756,6 +756,23 @@ check_for_string_or_list_or_dict_arg(typval_T *args, int idx)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
* Give an error and return FAIL unless "args[idx]" is a list or a blob.
|
||||||
*/
|
*/
|
||||||
|
@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3894,
|
||||||
/**/
|
/**/
|
||||||
3893,
|
3893,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user