1
0
forked from aniani/vim

patch 8.2.3188: Vim9: argument types are not checked at compile time

Problem:    Vim9: argument types are not checked at compile time.
Solution:   Add several more type checks, also at runtime. (Yegappan
            Lakshmanan, closes #8587)
This commit is contained in:
Yegappan Lakshmanan
2021-07-20 17:51:51 +02:00
committed by Bram Moolenaar
parent 9bb0dad0d8
commit 83494b4ac6
34 changed files with 1417 additions and 299 deletions

View File

@@ -823,6 +823,11 @@ flatten_common(typval_T *argvars, typval_T *rettv, int make_copy)
long maxdepth;
int error = FALSE;
if (in_vim9script()
&& (check_for_list_arg(argvars, 0) == FAIL
|| check_for_opt_number_arg(argvars, 1) == FAIL))
return;
if (argvars[0].v_type != VAR_LIST)
{
semsg(_(e_listarg), "flatten()");
@@ -1267,6 +1272,11 @@ f_join(typval_T *argvars, typval_T *rettv)
garray_T ga;
char_u *sep;
if (in_vim9script()
&& (check_for_list_arg(argvars, 0) == FAIL
|| check_for_opt_string_arg(argvars, 1) == FAIL))
return;
if (argvars[0].v_type != VAR_LIST)
{
emsg(_(e_listreq));
@@ -1470,6 +1480,12 @@ f_list2str(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (in_vim9script()
&& (check_for_list_arg(argvars, 0) == FAIL
|| check_for_opt_bool_arg(argvars, 1) == FAIL))
return;
if (argvars[0].v_type != VAR_LIST)
{
emsg(_(e_invarg));
@@ -1522,6 +1538,12 @@ list_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg)
int error = FALSE;
long idx;
if (in_vim9script()
&& (check_for_list_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_number_arg(argvars, 2) == FAIL))
return;
if ((l = argvars[0].vval.v_list) == NULL
|| value_check_lock(l->lv_lock, arg_errmsg, TRUE))
return;
@@ -2489,6 +2511,16 @@ f_count(typval_T *argvars, typval_T *rettv)
int ic = FALSE;
int error = FALSE;
if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING
&& argvars[0].v_type != VAR_LIST
&& argvars[0].v_type != VAR_DICT
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_opt_bool_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& check_for_opt_number_arg(argvars, 3) == FAIL)))
return;
if (argvars[2].v_type != VAR_UNKNOWN)
ic = (int)tv_get_bool_chk(&argvars[2], &error);