0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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

@ -415,9 +415,16 @@ blob_set_range(blob_T *dest, long n1, long n2, typval_T *src)
blob_remove(typval_T *argvars, typval_T *rettv) blob_remove(typval_T *argvars, typval_T *rettv)
{ {
int error = FALSE; int error = FALSE;
long idx = (long)tv_get_number_chk(&argvars[1], &error); long idx;
long end; long end;
if (in_vim9script()
&& (check_for_blob_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_number_arg(argvars, 2) == FAIL))
return;
idx = (long)tv_get_number_chk(&argvars[1], &error);
if (!error) if (!error)
{ {
blob_T *b = argvars[0].vval.v_blob; blob_T *b = argvars[0].vval.v_blob;

View File

@ -4270,6 +4270,11 @@ ch_expr_common(typval_T *argvars, typval_T *rettv, int eval)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (in_vim9script()
&& (check_for_chan_or_job_arg(argvars, 0) == FAIL
|| check_for_opt_dict_arg(argvars, 2) == FAIL))
return;
channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0); channel = get_channel_arg(&argvars[0], TRUE, FALSE, 0);
if (channel == NULL) if (channel == NULL)
return; return;
@ -4330,6 +4335,12 @@ ch_raw_common(typval_T *argvars, typval_T *rettv, int eval)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (in_vim9script()
&& (check_for_chan_or_job_arg(argvars, 0) == FAIL
|| check_for_string_or_blob_arg(argvars, 1) == FAIL
|| check_for_opt_dict_arg(argvars, 2) == FAIL))
return;
if (argvars[1].v_type == VAR_BLOB) if (argvars[1].v_type == VAR_BLOB)
{ {
text = argvars[1].vval.v_blob->bv_ga.ga_data; text = argvars[1].vval.v_blob->bv_ga.ga_data;
@ -4815,9 +4826,16 @@ f_ch_close_in(typval_T *argvars, typval_T *rettv UNUSED)
void void
f_ch_getbufnr(typval_T *argvars, typval_T *rettv) f_ch_getbufnr(typval_T *argvars, typval_T *rettv)
{ {
channel_T *channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0); channel_T *channel;
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
if (in_vim9script()
&& (check_for_chan_or_job_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;
channel = get_channel_arg(&argvars[0], FALSE, FALSE, 0);
if (channel != NULL) if (channel != NULL)
{ {
char_u *what = tv_get_string(&argvars[1]); char_u *what = tv_get_string(&argvars[1]);
@ -4894,6 +4912,7 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
// Don't open a file in restricted mode. // Don't open a file in restricted mode.
if (check_restricted() || check_secure()) if (check_restricted() || check_secure())
return; return;
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL)) || check_for_string_arg(argvars, 1) == FAIL))

View File

@ -793,6 +793,15 @@ f_remote_expr(typval_T *argvars UNUSED, typval_T *rettv)
{ {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL
|| check_for_opt_string_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& check_for_opt_number_arg(argvars, 3) == FAIL)))
return;
#ifdef FEAT_CLIENTSERVER #ifdef FEAT_CLIENTSERVER
remote_common(argvars, rettv, TRUE); remote_common(argvars, rettv, TRUE);
#endif #endif
@ -891,8 +900,7 @@ f_remote_read(typval_T *argvars UNUSED, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_number_arg(argvars, 1) == FAIL))
&& check_for_number_arg(argvars, 1) == FAIL)))
return; return;
serverid = tv_get_string_chk(&argvars[0]); serverid = tv_get_string_chk(&argvars[0]);
@ -932,6 +940,13 @@ f_remote_send(typval_T *argvars UNUSED, typval_T *rettv)
{ {
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL
|| check_for_opt_string_arg(argvars, 2) == FAIL))
return;
#ifdef FEAT_CLIENTSERVER #ifdef FEAT_CLIENTSERVER
remote_common(argvars, rettv, FALSE); remote_common(argvars, rettv, FALSE);
#endif #endif

View File

@ -2891,6 +2891,12 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
| WILD_NO_BEEP; | WILD_NO_BEEP;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL
|| check_for_opt_bool_arg(argvars, 2) == FAIL))
return;
if (argvars[1].v_type != VAR_STRING) if (argvars[1].v_type != VAR_STRING)
{ {
semsg(_(e_invarg2), "type must be a string"); semsg(_(e_invarg2), "type must be a string");

View File

@ -599,8 +599,7 @@ f_histget(typval_T *argvars UNUSED, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_number_arg(argvars, 1) == FAIL))
&& check_for_number_arg(argvars, 1) == FAIL)))
return; return;
str = tv_get_string_chk(&argvars[0]); // NULL on type error str = tv_get_string_chk(&argvars[0]); // NULL on type error

View File

@ -1340,6 +1340,11 @@ dict_remove(typval_T *argvars, typval_T *rettv, char_u *arg_errmsg)
char_u *key; char_u *key;
dictitem_T *di; dictitem_T *di;
if (in_vim9script()
&& (check_for_dict_arg(argvars, 0) == FAIL
|| check_for_string_or_number_arg(argvars, 1) == FAIL))
return;
if (argvars[2].v_type != VAR_UNKNOWN) if (argvars[2].v_type != VAR_UNKNOWN)
semsg(_(e_toomanyarg), "remove()"); semsg(_(e_toomanyarg), "remove()");
else if ((d = argvars[0].vval.v_dict) != NULL else if ((d = argvars[0].vval.v_dict) != NULL

View File

@ -3294,9 +3294,7 @@ f_diff_hlID(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
int col; int col;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars,0) == FAIL
&& argvars[0].v_type != VAR_NUMBER
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_number_arg(argvars, 1) == FAIL)) || check_for_number_arg(argvars, 1) == FAIL))
return; return;

View File

@ -520,3 +520,9 @@ EXTERN char e_digraph_argument_must_be_one_character_str[]
EXTERN char e_setdigraphlist_argument_must_be_list_of_lists_with_two_items[] EXTERN char e_setdigraphlist_argument_must_be_list_of_lists_with_two_items[]
INIT(= N_("E1216: setdigraphlist() argument must be a list of lists with two items")); INIT(= N_("E1216: setdigraphlist() argument must be a list of lists with two items"));
#endif #endif
EXTERN char e_blob_required_for_argument_nr[]
INIT(= N_("E1217: Blob required for argument %d"));
EXTERN char e_chan_or_job_required_for_argument_nr[]
INIT(= N_("E1218: Channel or Job required for argument %d"));
EXTERN char e_job_required_for_argument_nr[]
INIT(= N_("E1219: Job required for argument %d"));

View File

@ -4184,6 +4184,15 @@ check_can_index(typval_T *rettv, int evaluate, int verbose)
void void
f_slice(typval_T *argvars, typval_T *rettv) f_slice(typval_T *argvars, typval_T *rettv)
{ {
if (in_vim9script()
&& ((argvars[0].v_type != VAR_LIST
&& argvars[0].v_type != VAR_BLOB
&& argvars[0].v_type != VAR_STRING
&& check_for_list_arg(argvars, 0) == FAIL)
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_number_arg(argvars, 2) == FAIL))
return;
if (check_can_index(argvars, TRUE, FALSE) == OK) if (check_can_index(argvars, TRUE, FALSE) == OK)
{ {
copy_tv(argvars, rettv); copy_tv(argvars, rettv);

View File

@ -387,6 +387,12 @@ f_bufnr(typval_T *argvars, typval_T *rettv)
int error = FALSE; int error = FALSE;
char_u *name; char_u *name;
if (in_vim9script()
&& (check_for_opt_string_or_number_arg(argvars, 0) == FAIL
|| (argvars[0].v_type != VAR_UNKNOWN
&& check_for_opt_bool_arg(argvars, 1) == FAIL)))
return;
if (argvars[0].v_type == VAR_UNKNOWN) if (argvars[0].v_type == VAR_UNKNOWN)
buf = curbuf; buf = curbuf;
else else
@ -459,6 +465,12 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
tabpage_T *tp; tabpage_T *tp;
win_T *wp; win_T *wp;
if (in_vim9script()
&& (check_for_buffer_arg(argvars, 0) == FAIL
|| check_for_lnum_arg(argvars, 1) == FAIL
|| check_for_opt_lnum_arg(argvars, 2) == FAIL))
return;
buf = tv_get_buf(&argvars[0], FALSE); buf = tv_get_buf(&argvars[0], FALSE);
if (buf == NULL) if (buf == NULL)
{ {
@ -727,6 +739,12 @@ f_getbufline(typval_T *argvars, typval_T *rettv)
linenr_T end = 1; linenr_T end = 1;
buf_T *buf; buf_T *buf;
if (in_vim9script()
&& (check_for_buffer_arg(argvars, 0) == FAIL
|| check_for_lnum_arg(argvars, 1) == FAIL
|| check_for_opt_lnum_arg(argvars, 2) == FAIL))
return;
buf = tv_get_buf_from_arg(&argvars[0]); buf = tv_get_buf_from_arg(&argvars[0]);
if (buf != NULL) if (buf != NULL)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -4039,6 +4039,11 @@ f_gettabvar(typval_T *argvars, typval_T *rettv)
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL; rettv->vval.v_string = NULL;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;
varname = tv_get_string_chk(&argvars[1]); varname = tv_get_string_chk(&argvars[1]);
tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
if (tp != NULL && varname != NULL) if (tp != NULL && varname != NULL)
@ -4073,6 +4078,12 @@ f_gettabvar(typval_T *argvars, typval_T *rettv)
void void
f_gettabwinvar(typval_T *argvars, typval_T *rettv) f_gettabwinvar(typval_T *argvars, typval_T *rettv)
{ {
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_string_arg(argvars, 2) == FAIL))
return;
getwinvar(argvars, rettv, 1); getwinvar(argvars, rettv, 1);
} }
@ -4082,6 +4093,11 @@ f_gettabwinvar(typval_T *argvars, typval_T *rettv)
void void
f_getwinvar(typval_T *argvars, typval_T *rettv) f_getwinvar(typval_T *argvars, typval_T *rettv)
{ {
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;
getwinvar(argvars, rettv, 0); getwinvar(argvars, rettv, 0);
} }
@ -4165,6 +4181,11 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
if (check_secure()) if (check_secure())
return; return;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;
tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL)); tp = find_tabpage((int)tv_get_number_chk(&argvars[0], NULL));
varname = tv_get_string_chk(&argvars[1]); varname = tv_get_string_chk(&argvars[1]);
varp = &argvars[2]; varp = &argvars[2];
@ -4195,6 +4216,12 @@ f_settabvar(typval_T *argvars, typval_T *rettv UNUSED)
void void
f_settabwinvar(typval_T *argvars, typval_T *rettv UNUSED) f_settabwinvar(typval_T *argvars, typval_T *rettv UNUSED)
{ {
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_string_arg(argvars, 2) == FAIL))
return;
setwinvar(argvars, 1); setwinvar(argvars, 1);
} }
@ -4204,6 +4231,11 @@ f_settabwinvar(typval_T *argvars, typval_T *rettv UNUSED)
void void
f_setwinvar(typval_T *argvars, typval_T *rettv UNUSED) f_setwinvar(typval_T *argvars, typval_T *rettv UNUSED)
{ {
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL))
return;
setwinvar(argvars, 0); setwinvar(argvars, 0);
} }

View File

@ -655,8 +655,7 @@ f_tabpagewinnr(typval_T *argvars UNUSED, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL && (check_for_number_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_string_arg(argvars, 1) == FAIL))
&& check_for_string_arg(argvars, 1) == FAIL)))
return; return;
tp = find_tabpage((int)tv_get_number(&argvars[0])); tp = find_tabpage((int)tv_get_number(&argvars[0]));
@ -834,6 +833,12 @@ f_win_splitmove(typval_T *argvars, typval_T *rettv)
win_T *targetwin; win_T *targetwin;
int flags = 0, size = 0; int flags = 0, size = 0;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_dict_arg(argvars, 2) == FAIL))
return;
wp = find_win_by_nr_or_id(&argvars[0]); wp = find_win_by_nr_or_id(&argvars[0]);
targetwin = find_win_by_nr_or_id(&argvars[1]); targetwin = find_win_by_nr_or_id(&argvars[1]);

View File

@ -1254,6 +1254,15 @@ f_glob(typval_T *argvars, typval_T *rettv)
expand_T xpc; expand_T xpc;
int error = FALSE; int error = FALSE;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_opt_bool_arg(argvars, 1) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
&& (check_for_opt_bool_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& check_for_opt_bool_arg(argvars, 3) == FAIL)))))
return;
// When the optional second argument is non-zero, don't remove matches // When the optional second argument is non-zero, don't remove matches
// for 'wildignore' and don't put matches for 'suffixes' at the end. // for 'wildignore' and don't put matches for 'suffixes' at the end.
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
@ -1318,11 +1327,23 @@ f_globpath(typval_T *argvars, typval_T *rettv)
{ {
int flags = WILD_IGNORE_COMPLETESLASH; int flags = WILD_IGNORE_COMPLETESLASH;
char_u buf1[NUMBUFLEN]; char_u buf1[NUMBUFLEN];
char_u *file = tv_get_string_buf_chk(&argvars[1], buf1); char_u *file;
int error = FALSE; int error = FALSE;
garray_T ga; garray_T ga;
int i; int i;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL
|| check_for_opt_bool_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& (check_for_opt_bool_arg(argvars, 3) == FAIL
|| (argvars[3].v_type != VAR_UNKNOWN
&& check_for_opt_bool_arg(argvars, 4) == FAIL)))))
return;
file = tv_get_string_buf_chk(&argvars[1], buf1);
// When the optional second argument is non-zero, don't remove matches // When the optional second argument is non-zero, don't remove matches
// for 'wildignore' and don't put matches for 'suffixes' at the end. // for 'wildignore' and don't put matches for 'suffixes' at the end.
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
@ -1449,8 +1470,7 @@ f_pathshorten(typval_T *argvars, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_number_arg(argvars, 1) == FAIL))
&& check_for_number_arg(argvars, 1) == FAIL)))
return; return;
if (argvars[1].v_type != VAR_UNKNOWN) if (argvars[1].v_type != VAR_UNKNOWN)
@ -2423,10 +2443,12 @@ f_browse(typval_T *argvars UNUSED, typval_T *rettv)
int error = FALSE; int error = FALSE;
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 1) == FAIL && (check_for_bool_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL
|| check_for_string_arg(argvars, 2) == FAIL || check_for_string_arg(argvars, 2) == FAIL
|| check_for_string_arg(argvars, 3) == FAIL)) || check_for_string_arg(argvars, 3) == FAIL))
return; return;
save = (int)tv_get_number_chk(&argvars[0], &error); save = (int)tv_get_number_chk(&argvars[0], &error);
title = tv_get_string_chk(&argvars[1]); title = tv_get_string_chk(&argvars[1]);
initdir = tv_get_string_buf_chk(&argvars[2], buf); initdir = tv_get_string_buf_chk(&argvars[2], buf);

View File

@ -1700,10 +1700,11 @@ EXTERN char e_readonlyvar[] INIT(= N_("E46: Cannot change read-only variable \"%
EXTERN char e_readonlysbx[] INIT(= N_("E794: Cannot set variable in the sandbox: \"%s\"")); EXTERN char e_readonlysbx[] INIT(= N_("E794: Cannot set variable in the sandbox: \"%s\""));
EXTERN char e_stringreq[] INIT(= N_("E928: String required")); EXTERN char e_stringreq[] INIT(= N_("E928: String required"));
EXTERN char e_numberreq[] INIT(= N_("E889: Number required")); EXTERN char e_numberreq[] INIT(= N_("E889: Number required"));
EXTERN char e_boolreq[] INIT(= N_("E839: Number required")); EXTERN char e_boolreq[] INIT(= N_("E839: Bool required"));
EXTERN char e_emptykey[] INIT(= N_("E713: Cannot use empty key for Dictionary")); EXTERN char e_emptykey[] INIT(= N_("E713: Cannot use empty key for Dictionary"));
EXTERN char e_dictreq[] INIT(= N_("E715: Dictionary required")); EXTERN char e_dictreq[] INIT(= N_("E715: Dictionary required"));
EXTERN char e_listidx[] INIT(= N_("E684: list index out of range: %ld")); EXTERN char e_listidx[] INIT(= N_("E684: list index out of range: %ld"));
EXTERN char e_blobreq[] INIT(= N_("E538: Dictionary required"));
EXTERN char e_blobidx[] INIT(= N_("E979: Blob index out of range: %ld")); EXTERN char e_blobidx[] INIT(= N_("E979: Blob index out of range: %ld"));
EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob")); EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob"));
EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s")); EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s"));
@ -1810,6 +1811,8 @@ EXTERN char e_lock_unlock[] INIT(= N_("E940: Cannot lock or unlock variable %s")
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS) #if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
EXTERN char e_alloc_color[] INIT(= N_("E254: Cannot allocate color %s")); EXTERN char e_alloc_color[] INIT(= N_("E254: Cannot allocate color %s"));
#endif #endif
EXTERN char e_chan_or_job_req[] INIT(= N_("E706: Channel or Job required"));
EXTERN char e_jobreq[] INIT(= N_("E693: Job required"));
EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM")); EXTERN char top_bot_msg[] INIT(= N_("search hit TOP, continuing at BOTTOM"));
EXTERN char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP")); EXTERN char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP"));

View File

@ -2436,6 +2436,11 @@ f_complete(typval_T *argvars, typval_T *rettv UNUSED)
int startcol; int startcol;
int save_textlock = textlock; int save_textlock = textlock;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_list_arg(argvars, 1) == FAIL))
return;
if ((State & INSERT) == 0) if ((State & INSERT) == 0)
{ {
emsg(_("E785: complete() can only be used in Insert mode")); emsg(_("E785: complete() can only be used in Insert mode"));
@ -2468,6 +2473,12 @@ f_complete(typval_T *argvars, typval_T *rettv UNUSED)
void void
f_complete_add(typval_T *argvars, typval_T *rettv) f_complete_add(typval_T *argvars, typval_T *rettv)
{ {
if (in_vim9script()
&& (argvars[0].v_type != VAR_DICT
&& argvars[0].v_type != VAR_STRING
&& check_for_string_arg(argvars, 0) == FAIL))
return;
rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, FALSE); rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, FALSE);
} }

View File

@ -1726,9 +1726,7 @@ f_prompt_setprompt(typval_T *argvars, typval_T *rettv UNUSED)
char_u *text; char_u *text;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars, 0) == FAIL
&& argvars[0].v_type != VAR_NUMBER
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_string_arg(argvars, 1) == FAIL)) || check_for_string_arg(argvars, 1) == FAIL))
return; return;
@ -1875,9 +1873,15 @@ f_job_info(typval_T *argvars, typval_T *rettv)
void void
f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED) f_job_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
{ {
job_T *job = get_job_arg(&argvars[0]); job_T *job;
jobopt_T opt; jobopt_T opt;
if (in_vim9script()
&& (check_for_job_arg(argvars, 0) == FAIL
|| check_for_dict_arg(argvars, 1) == FAIL))
return;
job = get_job_arg(&argvars[0]);
if (job == NULL) if (job == NULL)
return; return;
clear_job_options(&opt); clear_job_options(&opt);
@ -1928,8 +1932,14 @@ f_job_status(typval_T *argvars, typval_T *rettv)
void void
f_job_stop(typval_T *argvars, typval_T *rettv) f_job_stop(typval_T *argvars, typval_T *rettv)
{ {
job_T *job = get_job_arg(&argvars[0]); job_T *job;
if (in_vim9script()
&& (check_for_job_arg(argvars, 0) == FAIL
|| check_for_opt_string_or_number_arg(argvars, 1) == FAIL))
return;
job = get_job_arg(&argvars[0]);
if (job != NULL) if (job != NULL)
rettv->vval.v_number = job_stop(job, argvars, NULL); rettv->vval.v_number = job_stop(job, argvars, NULL);
} }

View File

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

View File

@ -2316,6 +2316,12 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
int nowait; int nowait;
char_u *arg; char_u *arg;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_bool_arg(argvars, 1) == FAIL
|| check_for_dict_arg(argvars, 2) == FAIL))
return;
which = tv_get_string_buf_chk(&argvars[0], buf); which = tv_get_string_buf_chk(&argvars[0], buf);
if (which == NULL) if (which == NULL)
return; return;

View File

@ -1045,14 +1045,21 @@ f_setmatches(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
listitem_T *li; listitem_T *li;
dict_T *d; dict_T *d;
list_T *s = NULL; list_T *s = NULL;
win_T *win = get_optional_window(argvars, 1); win_T *win;
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
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) if (argvars[0].v_type != VAR_LIST)
{ {
emsg(_(e_listreq)); emsg(_(e_listreq));
return; return;
} }
win = get_optional_window(argvars, 1);
if (win == NULL) if (win == NULL)
return; return;

View File

@ -11,10 +11,24 @@ varnumber_T tv_get_bool_chk(typval_T *varp, int *denote);
float_T tv_get_float(typval_T *varp); float_T tv_get_float(typval_T *varp);
int check_for_string_arg(typval_T *args, int idx); int check_for_string_arg(typval_T *args, int idx);
int check_for_nonempty_string_arg(typval_T *args, int idx); int check_for_nonempty_string_arg(typval_T *args, int idx);
int check_for_opt_string_arg(typval_T *args, int idx);
int check_for_number_arg(typval_T *args, int idx); int check_for_number_arg(typval_T *args, int idx);
int check_for_opt_number_arg(typval_T *args, int idx);
int check_for_bool_arg(typval_T *args, int idx); int check_for_bool_arg(typval_T *args, int idx);
int check_for_opt_bool_arg(typval_T *args, int idx);
int check_for_list_arg(typval_T *args, int idx); int check_for_list_arg(typval_T *args, int idx);
int check_for_opt_list_arg(typval_T *args, int idx);
int check_for_dict_arg(typval_T *args, int idx); int check_for_dict_arg(typval_T *args, int idx);
int check_for_opt_dict_arg(typval_T *args, int idx);
int check_for_blob_arg(typval_T *args, int idx);
int check_for_chan_or_job_arg(typval_T *args, int idx);
int check_for_job_arg(typval_T *args, int idx);
int check_for_string_or_number_arg(typval_T *args, int idx);
int check_for_buffer_arg(typval_T *args, int idx);
int check_for_lnum_arg(typval_T *args, int idx);
int check_for_opt_lnum_arg(typval_T *args, int idx);
int check_for_opt_string_or_number_arg(typval_T *args, int idx);
int check_for_string_or_blob_arg(typval_T *args, int idx);
char_u *tv_get_string(typval_T *varp); char_u *tv_get_string(typval_T *varp);
char_u *tv_get_string_strict(typval_T *varp); char_u *tv_get_string_strict(typval_T *varp);
char_u *tv_get_string_buf(typval_T *varp, char_u *buf); char_u *tv_get_string_buf(typval_T *varp, char_u *buf);

View File

@ -8466,6 +8466,14 @@ f_setloclist(typval_T *argvars, typval_T *rettv)
rettv->vval.v_number = -1; rettv->vval.v_number = -1;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_list_arg(argvars, 1) == FAIL
|| check_for_opt_string_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& check_for_opt_dict_arg(argvars, 3) == FAIL)))
return;
win = find_win_by_nr_or_id(&argvars[0]); win = find_win_by_nr_or_id(&argvars[0]);
if (win != NULL) if (win != NULL)
set_qf_ll_list(win, &argvars[1], &argvars[2], &argvars[3], rettv); set_qf_ll_list(win, &argvars[1], &argvars[2], &argvars[3], rettv);
@ -8477,6 +8485,13 @@ f_setloclist(typval_T *argvars, typval_T *rettv)
void void
f_setqflist(typval_T *argvars, typval_T *rettv) f_setqflist(typval_T *argvars, typval_T *rettv)
{ {
if (in_vim9script()
&& (check_for_list_arg(argvars, 0) == FAIL
|| check_for_opt_string_arg(argvars, 1) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
&& check_for_opt_dict_arg(argvars, 2) == FAIL)))
return;
set_qf_ll_list(NULL, &argvars[0], &argvars[1], &argvars[2], rettv); set_qf_ll_list(NULL, &argvars[0], &argvars[1], &argvars[2], rettv);
} }
#endif #endif

View File

@ -1217,7 +1217,8 @@ first_submatch(regmmatch_T *rp)
do_search( do_search(
oparg_T *oap, // can be NULL oparg_T *oap, // can be NULL
int dirc, // '/' or '?' int dirc, // '/' or '?'
int search_delim, // the delimiter for the search, e.g. '%' in s%regex%replacement% int search_delim, // the delimiter for the search, e.g. '%' in
// s%regex%replacement%
char_u *pat, char_u *pat,
long count, long count,
int options, int options,
@ -1476,11 +1477,11 @@ do_search(
msgbuf = trunc; msgbuf = trunc;
} }
#ifdef FEAT_RIGHTLEFT #ifdef FEAT_RIGHTLEFT
// The search pattern could be shown on the right in rightleft // The search pattern could be shown on the right in
// mode, but the 'ruler' and 'showcmd' area use it too, thus // rightleft mode, but the 'ruler' and 'showcmd' area use
// it would be blanked out again very soon. Show it on the // it too, thus it would be blanked out again very soon.
// left, but do reverse the text. // Show it on the left, but do reverse the text.
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
{ {
char_u *r; char_u *r;
@ -1503,7 +1504,7 @@ do_search(
vim_memset(msgbuf + pat_len, ' ', r - msgbuf); vim_memset(msgbuf + pat_len, ' ', r - msgbuf);
} }
} }
#endif #endif
msg_outtrans(msgbuf); msg_outtrans(msgbuf);
msg_clr_eos(); msg_clr_eos();
msg_check(); msg_check();
@ -1548,6 +1549,9 @@ do_search(
} }
} }
/*
* The actual search.
*/
c = searchit(curwin, curbuf, &pos, NULL, c = searchit(curwin, curbuf, &pos, NULL,
dirc == '/' ? FORWARD : BACKWARD, dirc == '/' ? FORWARD : BACKWARD,
searchstr, count, spats[0].off.end + (options & searchstr, count, spats[0].off.end + (options &
@ -1557,7 +1561,7 @@ do_search(
RE_LAST, sia); RE_LAST, sia);
if (dircp != NULL) if (dircp != NULL)
*dircp = search_delim; // restore second '/' or '?' for normal_cmd() *dircp = search_delim; // restore second '/' or '?' for normal_cmd()
if (!shortmess(SHM_SEARCH) if (!shortmess(SHM_SEARCH)
&& ((dirc == '/' && LT_POS(pos, curwin->w_cursor)) && ((dirc == '/' && LT_POS(pos, curwin->w_cursor))
@ -4794,6 +4798,12 @@ do_fuzzymatch(typval_T *argvars, typval_T *rettv, int retmatchpos)
int ret; int ret;
int matchseq = FALSE; int matchseq = FALSE;
if (in_vim9script()
&& (check_for_list_arg(argvars, 0) == FAIL
|| check_for_string_arg(argvars, 1) == FAIL
|| check_for_opt_dict_arg(argvars, 2) == FAIL))
return;
CLEAR_POINTER(&cb); CLEAR_POINTER(&cb);
// validate and get the arguments // validate and get the arguments

View File

@ -2300,6 +2300,12 @@ f_sign_getplaced(typval_T *argvars, typval_T *rettv)
if (rettv_list_alloc_id(rettv, aid_sign_getplaced) != OK) if (rettv_list_alloc_id(rettv, aid_sign_getplaced) != OK)
return; return;
if (in_vim9script()
&& (check_for_opt_string_or_number_arg(argvars, 0) == FAIL
|| (argvars[0].v_type != VAR_UNKNOWN
&& check_for_opt_dict_arg(argvars, 1) == FAIL)))
return;
if (argvars[0].v_type != VAR_UNKNOWN) if (argvars[0].v_type != VAR_UNKNOWN)
{ {
// get signs placed in the specified buffer // get signs placed in the specified buffer

View File

@ -904,8 +904,7 @@ f_str2list(typval_T *argvars, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_bool_arg(argvars, 1) == FAIL))
&& check_for_bool_arg(argvars, 1) == FAIL)))
return; return;
if (argvars[1].v_type != VAR_UNKNOWN) if (argvars[1].v_type != VAR_UNKNOWN)
@ -1116,8 +1115,7 @@ f_strchars(typval_T *argvars, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_bool_arg(argvars, 1) == FAIL))
&& check_for_bool_arg(argvars, 1) == FAIL)))
return; return;
if (argvars[1].v_type != VAR_UNKNOWN) if (argvars[1].v_type != VAR_UNKNOWN)
@ -1141,8 +1139,7 @@ f_strdisplaywidth(typval_T *argvars, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_number_arg(argvars, 1) == FAIL))
&& check_for_number_arg(argvars, 1) == FAIL)))
return; return;
s = tv_get_string(&argvars[0]); s = tv_get_string(&argvars[0]);
@ -1178,6 +1175,14 @@ f_strcharpart(typval_T *argvars, typval_T *rettv)
int slen; int slen;
int error = FALSE; int error = FALSE;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_number_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& check_for_opt_bool_arg(argvars, 3) == FAIL)))
return;
p = tv_get_string(&argvars[0]); p = tv_get_string(&argvars[0]);
slen = (int)STRLEN(p); slen = (int)STRLEN(p);
@ -1261,6 +1266,14 @@ f_strpart(typval_T *argvars, typval_T *rettv)
int slen; int slen;
int error = FALSE; int error = FALSE;
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_number_arg(argvars, 2) == FAIL
|| (argvars[2].v_type != VAR_UNKNOWN
&& check_for_opt_bool_arg(argvars, 3) == FAIL)))
return;
p = tv_get_string(&argvars[0]); p = tv_get_string(&argvars[0]);
slen = (int)STRLEN(p); slen = (int)STRLEN(p);

View File

@ -5928,11 +5928,17 @@ f_term_gettitle(typval_T *argvars, typval_T *rettv)
void void
f_term_gettty(typval_T *argvars, typval_T *rettv) f_term_gettty(typval_T *argvars, typval_T *rettv)
{ {
buf_T *buf = term_get_buf(argvars, "term_gettty()"); buf_T *buf;
char_u *p = NULL; char_u *p = NULL;
int num = 0; int num = 0;
if (in_vim9script()
&& (check_for_string_or_number_arg(argvars, 0) == FAIL
|| check_for_opt_bool_arg(argvars, 1) == FAIL))
return;
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
buf = term_get_buf(argvars, "term_gettty()");
if (buf == NULL) if (buf == NULL)
return; return;
if (argvars[1].v_type != VAR_UNKNOWN) if (argvars[1].v_type != VAR_UNKNOWN)
@ -6098,9 +6104,7 @@ f_term_sendkeys(typval_T *argvars, typval_T *rettv UNUSED)
term_T *term; term_T *term;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars, 0) == FAIL
&& argvars[0].v_type != VAR_NUMBER
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_string_arg(argvars, 1) == FAIL)) || check_for_string_arg(argvars, 1) == FAIL))
return; return;
@ -6175,9 +6179,16 @@ f_term_getansicolors(typval_T *argvars, typval_T *rettv)
void void
f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED) f_term_setansicolors(typval_T *argvars, typval_T *rettv UNUSED)
{ {
buf_T *buf = term_get_buf(argvars, "term_setansicolors()"); buf_T *buf;
term_T *term; term_T *term;
if (in_vim9script()
&& (check_for_opt_string_or_number_arg(argvars, 0) == FAIL
|| (argvars[0].v_type != VAR_UNKNOWN
&& check_for_opt_list_arg(argvars, 1) == FAIL)))
return;
buf = term_get_buf(argvars, "term_setansicolors()");
if (buf == NULL) if (buf == NULL)
return; return;
term = buf->b_term; term = buf->b_term;
@ -6206,9 +6217,7 @@ f_term_setapi(typval_T *argvars, typval_T *rettv UNUSED)
char_u *api; char_u *api;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars, 0) == FAIL
&& argvars[0].v_type != VAR_NUMBER
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_string_arg(argvars, 1) == FAIL)) || check_for_string_arg(argvars, 1) == FAIL))
return; return;
@ -6236,9 +6245,7 @@ f_term_setrestore(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
char_u *cmd; char_u *cmd;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars, 0) == FAIL
&& argvars[0].v_type != VAR_NUMBER
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_string_arg(argvars, 1) == FAIL)) || check_for_string_arg(argvars, 1) == FAIL))
return; return;
@ -6266,9 +6273,7 @@ f_term_setkill(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
char_u *how; char_u *how;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars, 0) == FAIL
&& argvars[0].v_type != VAR_NUMBER
&& check_for_string_arg(argvars, 0) == FAIL)
|| check_for_string_arg(argvars, 1) == FAIL)) || check_for_string_arg(argvars, 1) == FAIL))
return; return;
@ -6321,11 +6326,8 @@ f_term_wait(typval_T *argvars, typval_T *rettv UNUSED)
buf_T *buf; buf_T *buf;
if (in_vim9script() if (in_vim9script()
&& ((argvars[0].v_type != VAR_STRING && (check_for_string_or_number_arg(argvars, 0) == FAIL
&& argvars[0].v_type != VAR_NUMBER || check_for_opt_number_arg(argvars, 1) == FAIL))
&& check_for_string_arg(argvars, 0) == FAIL) ||
(argvars[1].v_type != VAR_UNKNOWN
&& check_for_number_arg(argvars, 1) == FAIL)))
return; return;
buf = term_get_buf(argvars, "term_wait()"); buf = term_get_buf(argvars, "term_wait()");

View File

@ -423,24 +423,6 @@ func Test_blob_func_remove()
END END
call CheckLegacyAndVim9Failure(lines, 'E979:') call CheckLegacyAndVim9Failure(lines, 'E979:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(1, 0)
END
call CheckLegacyAndVim9Failure(lines, 'E896:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, b)
END
call CheckLegacyAndVim9Failure(lines, 'E974:')
let lines =<< trim END
VAR b = 0zDEADBEEF
call remove(b, 1, [])
END
call CheckLegacyAndVim9Failure(lines, 'E745:')
let lines =<< trim END let lines =<< trim END
VAR b = 0zDEADBEEF VAR b = 0zDEADBEEF
call remove(test_null_blob(), 1, 2) call remove(test_null_blob(), 1, 2)
@ -504,16 +486,6 @@ func Test_blob_index()
call assert_equal(-1, index(test_null_blob(), 1)) call assert_equal(-1, index(test_null_blob(), 1))
END END
call CheckLegacyAndVim9Success(lines) call CheckLegacyAndVim9Success(lines)
let lines =<< trim END
echo index(0z11110111, 0x11, [])
END
call CheckLegacyAndVim9Failure(lines, 'E745:')
let lines =<< trim END
call index("asdf", 0)
END
call CheckLegacyAndVim9Failure(lines, 'E897:')
endfunc endfunc
func Test_blob_insert() func Test_blob_insert()

View File

@ -1093,11 +1093,11 @@ func Test_gui_mouse_event()
let &guioptions = save_guioptions let &guioptions = save_guioptions
" Test invalid parameters for test_gui_mouse_event() " Test invalid parameters for test_gui_mouse_event()
call assert_fails('call test_gui_mouse_event("", 1, 2, 3, 4)', 'E474:') call assert_fails('call test_gui_mouse_event("", 1, 2, 3, 4)', 'E1210:')
call assert_fails('call test_gui_mouse_event(0, "", 2, 3, 4)', 'E474:') call assert_fails('call test_gui_mouse_event(0, "", 2, 3, 4)', 'E1210:')
call assert_fails('call test_gui_mouse_event(0, 1, "", 3, 4)', 'E474:') call assert_fails('call test_gui_mouse_event(0, 1, "", 3, 4)', 'E1210:')
call assert_fails('call test_gui_mouse_event(0, 1, 2, "", 4)', 'E474:') call assert_fails('call test_gui_mouse_event(0, 1, 2, "", 4)', 'E1210:')
call assert_fails('call test_gui_mouse_event(0, 1, 2, 3, "")', 'E474:') call assert_fails('call test_gui_mouse_event(0, 1, 2, 3, "")', 'E1210:')
bw! bw!
call test_override('no_query_mouse', 0) call test_override('no_query_mouse', 0)

View File

@ -270,18 +270,10 @@ enddef
def Test_browse() def Test_browse()
CheckFeature browse CheckFeature browse
var lines =<< trim END CheckDefAndScriptFailure2(['browse(2, "title", "dir", "file")'], 'E1013: Argument 1: type mismatch, expected bool but got number', 'E1212: Bool required for argument 1')
browse(1, 2, 3, 4) CheckDefAndScriptFailure2(['browse(true, 2, "dir", "file")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
END CheckDefAndScriptFailure2(['browse(true, "title", 3, "file")'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2') CheckDefAndScriptFailure2(['browse(true, "title", "dir", 4)'], 'E1013: Argument 4: type mismatch, expected string but got number', 'E1174: String required for argument 4')
lines =<< trim END
browse(1, 'title', 3, 4)
END
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
lines =<< trim END
browse(1, 'title', 'dir', 4)
END
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
enddef enddef
def Test_browsedir() def Test_browsedir()
@ -330,6 +322,8 @@ def Test_bufnr()
buf = bufnr('Xdummy', true) buf = bufnr('Xdummy', true)
buf->assert_notequal(-1) buf->assert_notequal(-1)
exe 'bwipe! ' .. buf exe 'bwipe! ' .. buf
CheckDefAndScriptFailure2(['bufnr([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['bufnr(1, 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
enddef enddef
def Test_bufwinid() def Test_bufwinid()
@ -379,22 +373,53 @@ enddef
def Test_ch_canread() def Test_ch_canread()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefFailure(['ch_canread(10)'], 'E1013: Argument 1: type mismatch, expected channel but got number')
endif endif
CheckDefFailure(['ch_canread(10)'], 'E1013: Argument 1: type mismatch, expected channel but got number')
enddef enddef
def Test_ch_close() def Test_ch_close()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefFailure(['ch_close("c")'], 'E1013: Argument 1: type mismatch, expected channel but got string')
endif endif
CheckDefFailure(['ch_close("c")'], 'E1013: Argument 1: type mismatch, expected channel but got string')
enddef enddef
def Test_ch_close_in() def Test_ch_close_in()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool')
endif
enddef
def Test_ch_evalexpr()
if !has('channel')
CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_evalexpr(1, "a")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1218: Channel or Job required for argument 1')
CheckDefAndScriptFailure2(['ch_evalexpr(test_null_channel(), 1, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
endif
enddef
def Test_ch_evalraw()
if !has('channel')
CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_evalraw(1, "")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1218: Channel or Job required for argument 1')
CheckDefAndScriptFailure2(['ch_evalraw(test_null_channel(), 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['ch_evalraw(test_null_channel(), "", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
endif
enddef
def Test_ch_getbufnr()
if !has('channel')
CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_getbufnr(1, "a")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1218: Channel or Job required for argument 1')
CheckDefAndScriptFailure2(['ch_getbufnr(test_null_channel(), 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
endif endif
CheckDefFailure(['ch_close_in(true)'], 'E1013: Argument 1: type mismatch, expected channel but got bool')
enddef enddef
def Test_ch_getjob() def Test_ch_getjob()
@ -410,67 +435,94 @@ enddef
def Test_ch_info() def Test_ch_info()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>')
endif endif
CheckDefFailure(['ch_info([1])'], 'E1013: Argument 1: type mismatch, expected channel but got list<number>')
enddef enddef
def Test_ch_logfile() def Test_ch_logfile()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
endif else
assert_fails('ch_logfile(true)', 'E1174:') assert_fails('ch_logfile(true)', 'E1174:')
assert_fails('ch_logfile("foo", true)', 'E1174:') assert_fails('ch_logfile("foo", true)', 'E1174:')
CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') CheckDefAndScriptFailure2(['ch_logfile(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2') CheckDefAndScriptFailure2(['ch_logfile("a", true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2')
endif
enddef enddef
def Test_ch_open() def Test_ch_open()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2')
endif endif
CheckDefAndScriptFailure2(['ch_open({"a": 10}, "a")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['ch_open("a", [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2')
enddef enddef
def Test_ch_read() def Test_ch_read()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_read(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_read(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
endif endif
CheckDefAndScriptFailure2(['ch_read(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_read(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
enddef enddef
def Test_ch_readblob() def Test_ch_readblob()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_readblob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_readblob(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
endif endif
CheckDefAndScriptFailure2(['ch_readblob(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_readblob(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
enddef enddef
def Test_ch_readraw() def Test_ch_readraw()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_readraw(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_readraw(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
endif
enddef
def Test_ch_sendexpr()
if !has('channel')
CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_sendexpr(1, "a")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1218: Channel or Job required for argument 1')
CheckDefAndScriptFailure2(['ch_sendexpr(test_null_channel(), 1, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
endif
enddef
def Test_ch_sendraw()
if !has('channel')
CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_sendraw(1, "")'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E1218: Channel or Job required for argument 1')
CheckDefAndScriptFailure2(['ch_sendraw(test_null_channel(), 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['ch_sendraw(test_null_channel(), "", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
endif endif
CheckDefAndScriptFailure2(['ch_readraw(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_readraw(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
enddef enddef
def Test_ch_setoptions() def Test_ch_setoptions()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_setoptions(1, {})'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefFailure(['ch_setoptions(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>')
endif endif
CheckDefAndScriptFailure2(['ch_setoptions(1, {})'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefFailure(['ch_setoptions(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>')
enddef enddef
def Test_ch_status() def Test_ch_status()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['ch_status(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_status(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
endif endif
CheckDefAndScriptFailure2(['ch_status(1)'], 'E1013: Argument 1: type mismatch, expected channel but got number', 'E475: Invalid argument')
CheckDefAndScriptFailure2(['ch_status(test_null_channel(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E715: Dictionary required')
enddef enddef
def Test_char2nr() def Test_char2nr()
@ -538,6 +590,15 @@ def Test_col()
bw! bw!
enddef enddef
def Test_complete()
CheckDefAndScriptFailure2(['complete("1", [])'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['complete(1, {})'], 'E1013: Argument 2: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 2')
enddef
def Test_complete_add()
CheckDefAndScriptFailure2(['complete_add([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
enddef
def Test_complete_info() def Test_complete_info()
CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string') CheckDefFailure(['complete_info("")'], 'E1013: Argument 1: type mismatch, expected list<string> but got string')
CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>') CheckDefFailure(['complete_info({})'], 'E1013: Argument 1: type mismatch, expected list<string> but got dict<unknown>')
@ -576,6 +637,12 @@ enddef
def Test_count() def Test_count()
count('ABC ABC ABC', 'b', true)->assert_equal(3) count('ABC ABC ABC', 'b', true)->assert_equal(3)
count('ABC ABC ABC', 'b', false)->assert_equal(0) count('ABC ABC ABC', 'b', false)->assert_equal(0)
CheckDefAndScriptFailure2(['count(10, 1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['count("a", [1], 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
CheckDefAndScriptFailure2(['count("a", [1], 0, "b")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
count([1, 2, 2, 3], 2)->assert_equal(2)
count([1, 2, 2, 3], 2, false, 2)->assert_equal(1)
count({a: 1.1, b: 2.2, c: 1.1}, 1.1)->assert_equal(2)
enddef enddef
def Test_cursor() def Test_cursor()
@ -590,6 +657,9 @@ def Test_cursor()
cursor('2', 1) cursor('2', 1)
END END
CheckDefExecAndScriptFailure(lines, 'E1209:') CheckDefExecAndScriptFailure(lines, 'E1209:')
CheckDefAndScriptFailure2(['cursor(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected number but got blob', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['cursor(1, "2")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['cursor(1, 2, "3")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
enddef enddef
def Test_debugbreak() def Test_debugbreak()
@ -597,6 +667,10 @@ def Test_debugbreak()
CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') CheckDefFailure(['debugbreak("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef enddef
def Test_deepcopy()
CheckDefAndScriptFailure2(['deepcopy({}, 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
enddef
def Test_delete() def Test_delete()
var res: bool = delete('doesnotexist') var res: bool = delete('doesnotexist')
assert_equal(true, res) assert_equal(true, res)
@ -605,6 +679,12 @@ def Test_delete()
CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number') CheckDefFailure(['delete("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number')
enddef enddef
def Test_deletebufline()
CheckDefAndScriptFailure2(['deletebufline([], 2)'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['deletebufline("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['deletebufline("a", 2, 0z10)'], 'E1013: Argument 3: type mismatch, expected string but got blob', 'E1174: String required for argument 3')
enddef
def Test_diff_filler() def Test_diff_filler()
CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>') CheckDefFailure(['diff_filler([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>')
CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool') CheckDefFailure(['diff_filler(true)'], 'E1013: Argument 1: type mismatch, expected string but got bool')
@ -670,6 +750,9 @@ def Test_expand()
split SomeFile split SomeFile
expand('%', true, true)->assert_equal(['SomeFile']) expand('%', true, true)->assert_equal(['SomeFile'])
close close
CheckDefAndScriptFailure2(['expand(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['expand("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
CheckDefAndScriptFailure2(['expand("a", true, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef enddef
def Test_expandcmd() def Test_expandcmd()
@ -858,6 +941,8 @@ def Test_flattennew()
echo flatten([1, 2, 3]) echo flatten([1, 2, 3])
END END
CheckDefAndScriptFailure(lines, 'E1158:') CheckDefAndScriptFailure(lines, 'E1158:')
CheckDefAndScriptFailure2(['flattennew({})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['flattennew([], "1")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
enddef enddef
" Test for float functions argument type " Test for float functions argument type
@ -1033,6 +1118,9 @@ def Test_getbufline()
getbufline(-1, 1, '$')->assert_equal([]) getbufline(-1, 1, '$')->assert_equal([])
bwipe! bwipe!
CheckDefAndScriptFailure2(['getbufline([], 2)'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['getbufline("a", [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['getbufline("a", 2, 0z10)'], 'E1013: Argument 3: type mismatch, expected string but got blob', 'E1174: String required for argument 3')
enddef enddef
def Test_getchangelist() def Test_getchangelist()
@ -1062,24 +1150,14 @@ def Test_getcharstr()
CheckDefAndScriptFailure2(['getcharstr("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool') CheckDefAndScriptFailure2(['getcharstr("1")'], 'E1013: Argument 1: type mismatch, expected bool but got string', 'E1135: Using a String as a Bool')
enddef enddef
def Test_getenv()
if getenv('does-not_exist') == ''
assert_report('getenv() should return null')
endif
if getenv('does-not_exist') == null
else
assert_report('getenv() should return null')
endif
$SOMEENVVAR = 'some'
assert_equal('some', getenv('SOMEENVVAR'))
unlet $SOMEENVVAR
enddef
def Test_getcompletion() def Test_getcompletion()
set wildignore=*.vim,*~ set wildignore=*.vim,*~
var l = getcompletion('run', 'file', true) var l = getcompletion('run', 'file', true)
l->assert_equal([]) l->assert_equal([])
set wildignore& set wildignore&
CheckDefAndScriptFailure2(['getcompletion(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['getcompletion("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['getcompletion("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef enddef
def Test_getcurpos() def Test_getcurpos()
@ -1096,6 +1174,19 @@ def Test_getcwd()
CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string') CheckDefFailure(['getcwd(1, "x")'], 'E1013: Argument 2: type mismatch, expected number but got string')
enddef enddef
def Test_getenv()
if getenv('does-not_exist') == ''
assert_report('getenv() should return null')
endif
if getenv('does-not_exist') == null
else
assert_report('getenv() should return null')
endif
$SOMEENVVAR = 'some'
assert_equal('some', getenv('SOMEENVVAR'))
unlet $SOMEENVVAR
enddef
def Test_getfontname() def Test_getfontname()
CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') CheckDefFailure(['getfontname(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
enddef enddef
@ -1204,6 +1295,9 @@ def Test_getreg()
setreg('a', lines) setreg('a', lines)
getreg('a', true, true)->assert_equal(lines) getreg('a', true, true)->assert_equal(lines)
assert_fails('getreg("ab")', 'E1162:') assert_fails('getreg("ab")', 'E1162:')
CheckDefAndScriptFailure2(['getreg(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['getreg(".", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
CheckDefAndScriptFailure2(['getreg(".", 1, "b")'], 'E1013: Argument 3: type mismatch, expected bool but got string', 'E1212: Bool required for argument 3')
enddef enddef
def Test_getreg_return_type() def Test_getreg_return_type()
@ -1230,6 +1324,17 @@ def Test_gettabinfo()
CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') CheckDefFailure(['gettabinfo("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef enddef
def Test_gettabvar()
CheckDefAndScriptFailure2(['gettabvar("a", "b")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['gettabvar(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
enddef
def Test_gettabwinvar()
CheckDefAndScriptFailure2(['gettabwinvar("a", 2, "c")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['gettabwinvar(1, "b", "c", [])'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['gettabwinvar(1, 1, 3, {})'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
enddef
def Test_gettagstack() def Test_gettagstack()
CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') CheckDefFailure(['gettagstack("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef enddef
@ -1247,8 +1352,17 @@ def Test_getwinpos()
CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string') CheckDefFailure(['getwinpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef enddef
def Test_getwinvar()
CheckDefAndScriptFailure2(['getwinvar("a", "b")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['getwinvar(1, 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
enddef
def Test_glob() def Test_glob()
glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim']) glob('runtest.vim', true, true, true)->assert_equal(['runtest.vim'])
CheckDefAndScriptFailure2(['glob(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['glob("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
CheckDefAndScriptFailure2(['glob("a", 1, "b")'], 'E1013: Argument 3: type mismatch, expected bool but got string', 'E1212: Bool required for argument 3')
CheckDefAndScriptFailure2(['glob("a", 1, true, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4')
enddef enddef
def Test_glob2regpat() def Test_glob2regpat()
@ -1258,10 +1372,17 @@ enddef
def Test_globpath() def Test_globpath()
globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim']) globpath('.', 'runtest.vim', true, true, true)->assert_equal(['./runtest.vim'])
CheckDefAndScriptFailure2(['globpath(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['globpath("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['globpath("a", "b", "c")'], 'E1013: Argument 3: type mismatch, expected bool but got string', 'E1212: Bool required for argument 3')
CheckDefAndScriptFailure2(['globpath("a", "b", true, "d")'], 'E1013: Argument 4: type mismatch, expected bool but got string', 'E1212: Bool required for argument 4')
CheckDefAndScriptFailure2(['globpath("a", "b", true, false, "e")'], 'E1013: Argument 5: type mismatch, expected bool but got string', 'E1212: Bool required for argument 5')
enddef enddef
def Test_has() def Test_has()
has('eval', true)->assert_equal(1) has('eval', true)->assert_equal(1)
CheckDefAndScriptFailure2(['has(["a"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['has("a", "b")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2')
enddef enddef
def Test_has_key() def Test_has_key()
@ -1286,6 +1407,9 @@ def Test_hasmapto()
iabbrev foo foobar iabbrev foo foobar
hasmapto('foobar', 'i', true)->assert_equal(1) hasmapto('foobar', 'i', true)->assert_equal(1)
iunabbrev foo iunabbrev foo
CheckDefAndScriptFailure2(['hasmapto(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['hasmapto("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['hasmapto("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef enddef
def Test_histadd() def Test_histadd()
@ -1330,6 +1454,9 @@ enddef
def Test_index() def Test_index()
index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3) index(['a', 'b', 'a', 'B'], 'b', 2, true)->assert_equal(3)
CheckDefAndScriptFailure2(['index("a", "a")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['index([1], 1.1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
CheckDefAndScriptFailure2(['index(0z1020, [1], 1, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4')
enddef enddef
def Test_input() def Test_input()
@ -1458,6 +1585,16 @@ def Test_job_info_return_type()
endif endif
enddef enddef
def Test_job_setoptions()
if !has('job')
CheckFeature job
else
CheckDefAndScriptFailure2(['job_setoptions(test_null_channel(), {})'], 'E1013: Argument 1: type mismatch, expected job but got channel', 'E1219: Job required for argument 1')
CheckDefAndScriptFailure2(['job_setoptions(test_null_job(), [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
assert_equal('fail', job_status(test_null_job()))
endif
enddef
def Test_job_status() def Test_job_status()
if !has('job') if !has('job')
CheckFeature job CheckFeature job
@ -1467,6 +1604,20 @@ def Test_job_status()
endif endif
enddef enddef
def Test_job_stop()
if !has('job')
CheckFeature job
else
CheckDefAndScriptFailure2(['job_stop("a")'], 'E1013: Argument 1: type mismatch, expected job but got string', 'E1219: Job required for argument 1')
CheckDefAndScriptFailure2(['job_stop(test_null_job(), true)'], 'E1013: Argument 2: type mismatch, expected string but got bool', 'E1174: String required for argument 2')
endif
enddef
def Test_join()
CheckDefAndScriptFailure2(['join("abc")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['join([], 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
enddef
def Test_js_decode() def Test_js_decode()
CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number') CheckDefFailure(['js_decode(10)'], 'E1013: Argument 1: type mismatch, expected string but got number')
assert_equal([1, 2], js_decode('[1,2]')) assert_equal([1, 2], js_decode('[1,2]'))
@ -1512,6 +1663,11 @@ def Test_list2str_str2list_utf8()
list2str(l, true)->assert_equal(s) list2str(l, true)->assert_equal(s)
enddef enddef
def Test_list2str()
CheckDefAndScriptFailure2(['list2str(".", true)'], 'E1013: Argument 1: type mismatch, expected list<number> but got string', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['list2str([1], 0z10)'], 'E1013: Argument 2: type mismatch, expected bool but got blob', 'E1212: Bool required for argument 2')
enddef
def SID(): number def SID(): number
return expand('<SID>') return expand('<SID>')
->matchstr('<SNR>\zs\d\+\ze_$') ->matchstr('<SNR>\zs\d\+\ze_$')
@ -1526,6 +1682,27 @@ def Test_listener_remove()
CheckDefAndScriptFailure2(['listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number') CheckDefAndScriptFailure2(['listener_remove("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1030: Using a String as a Number')
enddef enddef
def Test_map_failure()
CheckFeature job
var lines =<< trim END
vim9script
writefile([], 'Xtmpfile')
silent e Xtmpfile
var d = {[bufnr('%')]: {a: 0}}
au BufReadPost * Func()
def Func()
if d->has_key('')
endif
eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
enddef
e
END
CheckScriptFailure(lines, 'E1013:')
au! BufReadPost
delete('Xtmpfile')
enddef
def Test_map_function_arg() def Test_map_function_arg()
var lines =<< trim END var lines =<< trim END
def MapOne(i: number, v: string): string def MapOne(i: number, v: string): string
@ -1591,12 +1768,10 @@ def Test_maparg()
rhs: 'bar', rhs: 'bar',
buffer: 0}) buffer: 0})
unmap foo unmap foo
enddef CheckDefAndScriptFailure2(['maparg(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['maparg("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
def Test_mapcheck() CheckDefAndScriptFailure2(['maparg("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
iabbrev foo foobar CheckDefAndScriptFailure2(['maparg("a", "b", true, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4')
mapcheck('foo', 'i', true)->assert_equal('foobar')
iunabbrev foo
enddef enddef
def Test_maparg_mapset() def Test_maparg_mapset()
@ -1607,25 +1782,19 @@ def Test_maparg_mapset()
nunmap <F3> nunmap <F3>
enddef enddef
def Test_map_failure() def Test_mapcheck()
CheckFeature job iabbrev foo foobar
mapcheck('foo', 'i', true)->assert_equal('foobar')
iunabbrev foo
CheckDefAndScriptFailure2(['mapcheck(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['mapcheck("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['mapcheck("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef
var lines =<< trim END def Test_mapset()
vim9script CheckDefAndScriptFailure2(['mapset(1, true, {})'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
writefile([], 'Xtmpfile') CheckDefAndScriptFailure2(['mapset("a", 2, {})'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
silent e Xtmpfile CheckDefAndScriptFailure2(['mapset("a", false, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
var d = {[bufnr('%')]: {a: 0}}
au BufReadPost * Func()
def Func()
if d->has_key('')
endif
eval d[expand('<abuf>')]->mapnew((_, v: dict<job>) => 0)
enddef
e
END
CheckScriptFailure(lines, 'E1013:')
au! BufReadPost
delete('Xtmpfile')
enddef enddef
def Test_match() def Test_match()
@ -1668,6 +1837,18 @@ def Test_matchend()
assert_equal(5, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2)) assert_equal(5, matchend(['a', 'b', 'c', 'b', 'd', 'b'], 'b', 2, 2))
enddef enddef
def Test_matchfuzzy()
CheckDefAndScriptFailure2(['matchfuzzy({}, "p")'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['matchfuzzy([], 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['matchfuzzy([], "a", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef
def Test_matchfuzzypos()
CheckDefAndScriptFailure2(['matchfuzzypos({}, "p")'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['matchfuzzypos([], 1)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['matchfuzzypos([], "a", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef
def Test_matchlist() def Test_matchlist()
CheckDefAndScriptFailure2(['matchlist(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1') CheckDefAndScriptFailure2(['matchlist(0z12, "p")'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['matchlist(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2') CheckDefAndScriptFailure2(['matchlist(["s"], [2])'], 'E1013: Argument 2: type mismatch, expected string but got list<number>', 'E1174: String required for argument 2')
@ -1781,6 +1962,8 @@ enddef
def Test_nr2char() def Test_nr2char()
nr2char(97, true)->assert_equal('a') nr2char(97, true)->assert_equal('a')
CheckDefAndScriptFailure2(['nr2char("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['nr2char(1, "a")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2')
enddef enddef
def Test_or() def Test_or()
@ -1906,9 +2089,22 @@ enddef
def Test_prompt_setprompt() def Test_prompt_setprompt()
if !has('channel') if !has('channel')
CheckFeature channel CheckFeature channel
else
CheckDefAndScriptFailure2(['prompt_setprompt([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['prompt_setprompt(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
endif endif
CheckDefAndScriptFailure2(['prompt_setprompt([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') enddef
CheckDefAndScriptFailure2(['prompt_setprompt(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
def Test_prop_add()
CheckDefAndScriptFailure2(['prop_add("a", 2, {})'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['prop_add(1, "b", {})'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['prop_add(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef
def Test_prop_clear()
CheckDefAndScriptFailure2(['prop_clear("a")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['prop_clear(1, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['prop_clear(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef enddef
def Test_prop_find() def Test_prop_find()
@ -1922,6 +2118,12 @@ def Test_prop_list()
CheckDefAndScriptFailure2(['prop_list(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2') CheckDefAndScriptFailure2(['prop_list(1, [])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 2')
enddef enddef
def Test_prop_remove()
CheckDefAndScriptFailure2(['prop_remove([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 1')
CheckDefAndScriptFailure2(['prop_remove({}, "a")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['prop_remove({}, 1, "b")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
enddef
def Test_prop_type_add() def Test_prop_type_add()
CheckDefAndScriptFailure2(['prop_type_add({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String') CheckDefAndScriptFailure2(['prop_type_add({"a": 10}, "b")'], 'E1013: Argument 1: type mismatch, expected string but got dict<number>', 'E731: Using a Dictionary as a String')
CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required') CheckDefAndScriptFailure2(['prop_type_add("a", "b")'], 'E1013: Argument 2: type mismatch, expected dict<any> but got string', 'E715: Dictionary required')
@ -2053,6 +2255,15 @@ def Test_reltimestr()
assert_true(type(reltimestr(reltime())) == v:t_string) assert_true(type(reltimestr(reltime())) == v:t_string)
enddef enddef
def Test_remote_expr()
CheckFeature clientserver
CheckEnv DISPLAY
CheckDefAndScriptFailure2(['remote_expr(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['remote_expr("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['remote_expr("a", "b", 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
CheckDefAndScriptFailure2(['remote_expr("a", "b", "c", "d")'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
enddef
def Test_remote_foreground() def Test_remote_foreground()
CheckFeature clientserver CheckFeature clientserver
# remote_foreground() doesn't fail on MS-Windows # remote_foreground() doesn't fail on MS-Windows
@ -2077,6 +2288,14 @@ def Test_remote_read()
CheckDefAndScriptFailure2(['remote_read("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2') CheckDefAndScriptFailure2(['remote_read("a", "x")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
enddef enddef
def Test_remote_send()
CheckFeature clientserver
CheckEnv DISPLAY
CheckDefAndScriptFailure2(['remote_send(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['remote_send("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['remote_send("a", "b", 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
enddef
def Test_remote_startserver() def Test_remote_startserver()
CheckFeature clientserver CheckFeature clientserver
CheckEnv DISPLAY CheckEnv DISPLAY
@ -2089,6 +2308,31 @@ def Test_remove_const_list()
assert_equal([3, 4], l) assert_equal([3, 4], l)
enddef enddef
def Test_remove()
CheckDefAndScriptFailure2(['remove("a", 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E896: Argument of remove() must be a List, Dictionary or Blob')
CheckDefAndScriptFailure2(['remove([], "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['remove([], 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
CheckDefAndScriptFailure2(['remove({}, 1.1)'], 'E1013: Argument 2: type mismatch, expected string but got float', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['remove(0z10, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['remove(0z20, 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
var l: any = [1, 2, 3, 4]
remove(l, 1)
assert_equal([1, 3, 4], l)
remove(l, 0, 1)
assert_equal([4], l)
var b: any = 0z1234.5678.90
remove(b, 1)
assert_equal(0z1256.7890, b)
remove(b, 1, 2)
assert_equal(0z1290, b)
var d: any = {a: 10, b: 20, c: 30}
remove(d, 'b')
assert_equal({a: 10, c: 30}, d)
var d2: any = {1: 'a', 2: 'b', 3: 'c'}
remove(d2, 2)
assert_equal({1: 'a', 3: 'c'}, d2)
enddef
def Test_remove_return_type() def Test_remove_return_type()
var l = remove({one: [1, 2], two: [3, 4]}, 'one') var l = remove({one: [1, 2], two: [3, 4]}, 'one')
var res = 0 var res = 0
@ -2202,6 +2446,13 @@ def Test_searchcount()
CheckDefAndScriptFailure2(['searchcount([1])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required') CheckDefAndScriptFailure2(['searchcount([1])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<number>', 'E715: Dictionary required')
enddef enddef
def Test_searchdecl()
searchdecl('blah', true, true)->assert_equal(1)
CheckDefAndScriptFailure2(['searchdecl(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['searchdecl("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
CheckDefAndScriptFailure2(['searchdecl("a", true, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef
def Test_searchpair() def Test_searchpair()
new new
setline(1, "here { and } there") setline(1, "here { and } there")
@ -2247,6 +2498,11 @@ def Test_server2client()
CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:') CheckDefAndScriptFailure2(['server2client("a", 10)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E573: Invalid server id used:')
enddef enddef
def Test_shellescape()
CheckDefAndScriptFailure2(['shellescape(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['shellescape("a", 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
enddef
def Test_set_get_bufline() def Test_set_get_bufline()
# similar to Test_setbufline_getbufline() # similar to Test_setbufline_getbufline()
var lines =<< trim END var lines =<< trim END
@ -2297,10 +2553,6 @@ def Test_set_get_bufline()
CheckDefAndScriptSuccess(lines) CheckDefAndScriptSuccess(lines)
enddef enddef
def Test_searchdecl()
searchdecl('blah', true, true)->assert_equal(1)
enddef
def Test_setbufvar() def Test_setbufvar()
setbufvar(bufnr('%'), '&syntax', 'vim') setbufvar(bufnr('%'), '&syntax', 'vim')
&syntax->assert_equal('vim') &syntax->assert_equal('vim')
@ -2326,23 +2578,6 @@ def Test_setbufvar()
getbufvar('%', 'myvar')->assert_equal(123) getbufvar('%', 'myvar')->assert_equal(123)
enddef enddef
def Test_setcharsearch()
CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string')
CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
var d: dict<any> = {char: 'x', forward: 1, until: 1}
setcharsearch(d)
assert_equal(d, getcharsearch())
enddef
def Test_setcmdpos()
CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_setfperm()
CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob')
enddef
def Test_setbufline() def Test_setbufline()
new new
var bnum = bufnr('%') var bnum = bufnr('%')
@ -2364,6 +2599,35 @@ def Test_setcellwidths()
CheckDefAndScriptFailure2(['setcellwidths({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required') CheckDefAndScriptFailure2(['setcellwidths({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
enddef enddef
def Test_setcharpos()
CheckDefAndScriptFailure2(['setcharpos(1, [])'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefFailure(['setcharpos(".", ["a"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
CheckDefAndScriptFailure2(['setcharpos(".", 1)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number', 'E1211: List required for argument 2')
enddef
def Test_setcharsearch()
CheckDefFailure(['setcharsearch("x")'], 'E1013: Argument 1: type mismatch, expected dict<any> but got string')
CheckDefFailure(['setcharsearch([])'], 'E1013: Argument 1: type mismatch, expected dict<any> but got list<unknown>')
var d: dict<any> = {char: 'x', forward: 1, until: 1}
setcharsearch(d)
assert_equal(d, getcharsearch())
enddef
def Test_setcmdpos()
CheckDefFailure(['setcmdpos("x")'], 'E1013: Argument 1: type mismatch, expected number but got string')
enddef
def Test_setcursorcharpos()
CheckDefAndScriptFailure2(['setcursorcharpos(0z10, 1)'], 'E1013: Argument 1: type mismatch, expected number but got blob', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['setcursorcharpos(1, "2")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['setcursorcharpos(1, 2, "3")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
enddef
def Test_setfperm()
CheckDefFailure(['setfperm(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['setfperm("a", 0z10)'], 'E1013: Argument 2: type mismatch, expected string but got blob')
enddef
def Test_setline() def Test_setline()
new new
setline(1, range(1, 4)) setline(1, range(1, 4))
@ -2383,6 +2647,27 @@ def Test_setloclist()
var what = {items: items} var what = {items: items}
setqflist([], ' ', what) setqflist([], ' ', what)
setloclist(0, [], ' ', what) setloclist(0, [], ' ', what)
CheckDefAndScriptFailure2(['setloclist("1", [])'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['setloclist(1, 2)'], 'E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2')
CheckDefAndScriptFailure2(['setloclist(1, [], 3)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
CheckDefAndScriptFailure2(['setloclist(1, [], "a", [])'], 'E1013: Argument 4: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 4')
enddef
def Test_setmatches()
CheckDefAndScriptFailure2(['setmatches({})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['setmatches([], "1")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
enddef
def Test_setpos()
CheckDefAndScriptFailure2(['setpos(1, [])'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefFailure(['setpos(".", ["a"])'], 'E1013: Argument 2: type mismatch, expected list<number> but got list<string>')
CheckDefAndScriptFailure2(['setpos(".", 1)'], 'E1013: Argument 2: type mismatch, expected list<number> but got number', 'E1211: List required for argument 2')
enddef
def Test_setqflist()
CheckDefAndScriptFailure2(['setqflist(1, "")'], 'E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['setqflist([], 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['setqflist([], "", [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef enddef
def Test_setreg() def Test_setreg()
@ -2393,6 +2678,28 @@ def Test_setreg()
assert_fails('setreg("ab", 0)', 'E1162:') assert_fails('setreg("ab", 0)', 'E1162:')
enddef enddef
def Test_settabvar()
CheckDefAndScriptFailure2(['settabvar("a", "b", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['settabvar(1, 2, "c")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
enddef
def Test_settabwinvar()
CheckDefAndScriptFailure2(['settabwinvar("a", 2, "c", true)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['settabwinvar(1, "b", "c", [])'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['settabwinvar(1, 1, 3, {})'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
enddef
def Test_settagstack()
CheckDefAndScriptFailure2(['settagstack(true, {})'], 'E1013: Argument 1: type mismatch, expected number but got bool', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['settagstack(1, [1])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 2')
CheckDefAndScriptFailure2(['settagstack(1, {}, 2)'], 'E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3')
enddef
def Test_setwinvar()
CheckDefAndScriptFailure2(['setwinvar("a", "b", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['setwinvar(1, 2, "c")'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
enddef
def Test_sha256() def Test_sha256()
CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number') CheckDefFailure(['sha256(100)'], 'E1013: Argument 1: type mismatch, expected string but got number')
CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob') CheckDefFailure(['sha256(0zABCD)'], 'E1013: Argument 1: type mismatch, expected string but got blob')
@ -2414,6 +2721,12 @@ def Test_sign_getdefined()
CheckDefAndScriptFailure2(['sign_getdefined(2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') CheckDefAndScriptFailure2(['sign_getdefined(2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
enddef enddef
def Test_sign_getplaced()
CheckDefAndScriptFailure2(['sign_getplaced(["x"])'], 'E1013: Argument 1: type mismatch, expected string but got list<string>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['sign_getplaced(1, ["a"])'], 'E1013: Argument 2: type mismatch, expected dict<any> but got list<string>', 'E1206: Dictionary required for argument 2')
CheckDefAndScriptFailure2(['sign_getplaced("a", 1.1)'], 'E1013: Argument 2: type mismatch, expected dict<any> but got float', 'E1206: Dictionary required for argument 2')
enddef
def Test_sign_placelist() def Test_sign_placelist()
CheckDefAndScriptFailure2(['sign_placelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required') CheckDefAndScriptFailure2(['sign_placelist("x")'], 'E1013: Argument 1: type mismatch, expected list<any> but got string', 'E714: List required')
CheckDefAndScriptFailure2(['sign_placelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required') CheckDefAndScriptFailure2(['sign_placelist({"a": 10})'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E714: List required')
@ -2461,6 +2774,9 @@ def Test_slice()
assert_equal(0z11, slice(0z001122334455, 1, -4)) assert_equal(0z11, slice(0z001122334455, 1, -4))
assert_equal(0z, slice(0z001122334455, 1, -5)) assert_equal(0z, slice(0z001122334455, 1, -5))
assert_equal(0z, slice(0z001122334455, 1, -6)) assert_equal(0z, slice(0z001122334455, 1, -6))
CheckDefAndScriptFailure2(['slice({"a": 10}, 1)'], 'E1013: Argument 1: type mismatch, expected list<any> but got dict<number>', 'E1211: List required for argument 1')
CheckDefAndScriptFailure2(['slice([1, 2, 3], "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['slice("abc", 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
enddef enddef
def Test_spellsuggest() def Test_spellsuggest()
@ -2469,6 +2785,9 @@ def Test_spellsuggest()
else else
spellsuggest('marrch', 1, true)->assert_equal(['March']) spellsuggest('marrch', 1, true)->assert_equal(['March'])
endif endif
CheckDefAndScriptFailure2(['spellsuggest(1)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['spellsuggest("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['spellsuggest("a", 1, 0z01)'], 'E1013: Argument 3: type mismatch, expected bool but got blob', 'E1212: Bool required for argument 3')
enddef enddef
def Test_sound_stop() def Test_sound_stop()
@ -2508,6 +2827,9 @@ enddef
def Test_split() def Test_split()
split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', '']) split(' aa bb ', '\W\+', true)->assert_equal(['', 'aa', 'bb', ''])
CheckDefAndScriptFailure2(['split(1, "b")'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['split("a", 2)'], 'E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2')
CheckDefAndScriptFailure2(['split("a", "b", 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef enddef
def Test_srand() def Test_srand()
@ -2557,6 +2879,13 @@ def Test_strcharlen()
strcharlen(99)->assert_equal(2) strcharlen(99)->assert_equal(2)
enddef enddef
def Test_strcharpart()
CheckDefAndScriptFailure2(['strcharpart(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['strcharpart("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['strcharpart("a", 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
CheckDefAndScriptFailure2(['strcharpart("a", 1, 1, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4')
enddef
def Test_strchars() def Test_strchars()
strchars("A\u20dd", true)->assert_equal(1) strchars("A\u20dd", true)->assert_equal(1)
CheckDefAndScriptFailure2(['strchars(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1') CheckDefAndScriptFailure2(['strchars(10)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
@ -2593,6 +2922,13 @@ def Test_strlen()
strlen(99)->assert_equal(2) strlen(99)->assert_equal(2)
enddef enddef
def Test_strpart()
CheckDefAndScriptFailure2(['strpart(1, 2)'], 'E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['strpart("a", "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['strpart("a", 1, "c")'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
CheckDefAndScriptFailure2(['strpart("a", 1, 1, 2)'], 'E1013: Argument 4: type mismatch, expected bool but got number', 'E1212: Bool required for argument 4')
enddef
def Test_strptime() def Test_strptime()
CheckFunction strptime CheckFunction strptime
CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number') CheckDefFailure(['strptime(10, "2021")'], 'E1013: Argument 1: type mismatch, expected string but got number')
@ -2626,6 +2962,8 @@ def Test_submatch()
var actual = substitute('A123456789', pat, Rep, '') var actual = substitute('A123456789', pat, Rep, '')
var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]" var expected = "[['A123456789'], ['1'], ['2'], ['3'], ['4'], ['5'], ['6'], ['7'], ['8'], ['9']]"
actual->assert_equal(expected) actual->assert_equal(expected)
CheckDefAndScriptFailure2(['submatch("x")'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['submatch(1, "a")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2')
enddef enddef
def Test_substitute() def Test_substitute()
@ -2653,6 +2991,9 @@ def Test_synID()
setline(1, "text") setline(1, "text")
synID(1, 1, true)->assert_equal(0) synID(1, 1, true)->assert_equal(0)
bwipe! bwipe!
CheckDefAndScriptFailure2(['synID(0z10, 1, true)'], 'E1013: Argument 1: type mismatch, expected string but got blob', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['synID("a", true, false)'], 'E1013: Argument 2: type mismatch, expected number but got bool', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['synID(1, 1, 2)'], 'E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3')
enddef enddef
def Test_synIDtrans() def Test_synIDtrans()
@ -2753,6 +3094,8 @@ def Test_term_gettty()
term_gettty(buf, true)->assert_notequal('') term_gettty(buf, true)->assert_notequal('')
StopShellInTerminal(buf) StopShellInTerminal(buf)
endif endif
CheckDefAndScriptFailure2(['term_gettty([1])'], 'E1013: Argument 1: type mismatch, expected string but got list<number>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['term_gettty(1, 2)'], 'E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2')
enddef enddef
def Test_term_sendkeys() def Test_term_sendkeys()
@ -2761,6 +3104,12 @@ def Test_term_sendkeys()
CheckDefAndScriptFailure2(['term_sendkeys(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2') CheckDefAndScriptFailure2(['term_sendkeys(1, [])'], 'E1013: Argument 2: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 2')
enddef enddef
def Test_term_setansicolors()
CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_setansicolors([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
CheckDefAndScriptFailure2(['term_setansicolors(10, {})'], 'E1013: Argument 2: type mismatch, expected list<any> but got dict<unknown>', 'E1211: List required for argument 2')
enddef
def Test_term_setapi() def Test_term_setapi()
CheckRunVimInTerminal CheckRunVimInTerminal
CheckDefAndScriptFailure2(['term_setapi([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1') CheckDefAndScriptFailure2(['term_setapi([], "p")'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E1174: String required for argument 1')
@ -2811,6 +3160,15 @@ def Test_test_getvalue()
CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument') CheckDefAndScriptFailure2(['test_getvalue(1.1)'], 'E1013: Argument 1: type mismatch, expected string but got float', 'E474: Invalid argument')
enddef enddef
def Test_test_gui_mouse_event()
CheckGui
CheckDefAndScriptFailure2(['test_gui_mouse_event(1.1, 1, 1, 1, 1)'], 'E1013: Argument 1: type mismatch, expected number but got float', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['test_gui_mouse_event(1, "1", 1, 1, 1)'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['test_gui_mouse_event(1, 1, "1", 1, 1)'], 'E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3')
CheckDefAndScriptFailure2(['test_gui_mouse_event(1, 1, 1, "1", 1)'], 'E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4')
CheckDefAndScriptFailure2(['test_gui_mouse_event(1, 1, 1, 1, "1")'], 'E1013: Argument 5: type mismatch, expected number but got string', 'E1210: Number required for argument 5')
enddef
def Test_test_ignore_error() def Test_test_ignore_error()
CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument') CheckDefAndScriptFailure2(['test_ignore_error([])'], 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 'E474: Invalid argument')
test_ignore_error('RESET') test_ignore_error('RESET')
@ -2845,6 +3203,11 @@ def Test_timer_info()
assert_equal([], timer_info()) assert_equal([], timer_info())
enddef enddef
def Test_timer_pause()
CheckDefAndScriptFailure2(['timer_pause("x", 1)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['timer_pause(1, "a")'], 'E1013: Argument 2: type mismatch, expected bool but got string', 'E1212: Bool required for argument 2')
enddef
def Test_timer_paused() def Test_timer_paused()
var id = timer_start(50, () => 0) var id = timer_start(50, () => 0)
timer_pause(id, true) timer_pause(id, true)
@ -2955,6 +3318,9 @@ def Test_win_splitmove()
split split
win_splitmove(1, 2, {vertical: true, rightbelow: true}) win_splitmove(1, 2, {vertical: true, rightbelow: true})
close close
CheckDefAndScriptFailure2(['win_splitmove("a", 2)'], 'E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1')
CheckDefAndScriptFailure2(['win_splitmove(1, "b")'], 'E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2')
CheckDefAndScriptFailure2(['win_splitmove(1, 2, [])'], 'E1013: Argument 3: type mismatch, expected dict<any> but got list<unknown>', 'E1206: Dictionary required for argument 3')
enddef enddef
def Test_winbufnr() def Test_winbufnr()

View File

@ -1246,15 +1246,12 @@ f_test_gui_mouse_event(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
int repeated_click; int repeated_click;
int_u mods; int_u mods;
if (argvars[0].v_type != VAR_NUMBER if (check_for_number_arg(argvars, 0) == FAIL
|| (argvars[1].v_type) != VAR_NUMBER || check_for_number_arg(argvars, 1) == FAIL
|| (argvars[2].v_type) != VAR_NUMBER || check_for_number_arg(argvars, 2) == FAIL
|| (argvars[3].v_type) != VAR_NUMBER || check_for_number_arg(argvars, 3) == FAIL
|| (argvars[4].v_type) != VAR_NUMBER) || check_for_number_arg(argvars, 4) == FAIL)
{
emsg(_(e_invarg));
return; return;
}
button = tv_get_number(&argvars[0]); button = tv_get_number(&argvars[0]);
row = tv_get_number(&argvars[1]); row = tv_get_number(&argvars[1]);

View File

@ -158,6 +158,12 @@ f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
linenr_T start_lnum; linenr_T start_lnum;
colnr_T start_col; colnr_T start_col;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_dict_arg(argvars, 2) == FAIL))
return;
start_lnum = tv_get_number(&argvars[0]); start_lnum = tv_get_number(&argvars[0]);
start_col = tv_get_number(&argvars[1]); start_col = tv_get_number(&argvars[1]);
if (start_col < 1) if (start_col < 1)
@ -532,12 +538,21 @@ text_prop_type_by_id(buf_T *buf, int id)
void void
f_prop_clear(typval_T *argvars, typval_T *rettv UNUSED) f_prop_clear(typval_T *argvars, typval_T *rettv UNUSED)
{ {
linenr_T start = tv_get_number(&argvars[0]); linenr_T start;
linenr_T end = start; linenr_T end;
linenr_T lnum; linenr_T lnum;
buf_T *buf = curbuf; buf_T *buf = curbuf;
int did_clear = FALSE; int did_clear = FALSE;
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_opt_number_arg(argvars, 1) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
&& check_for_opt_dict_arg(argvars, 2) == FAIL)))
return;
start = tv_get_number(&argvars[0]);
end = start;
if (argvars[1].v_type != VAR_UNKNOWN) if (argvars[1].v_type != VAR_UNKNOWN)
{ {
end = tv_get_number(&argvars[1]); end = tv_get_number(&argvars[1]);
@ -774,8 +789,7 @@ f_prop_list(typval_T *argvars, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL && (check_for_number_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN && || check_for_opt_dict_arg(argvars, 1) == FAIL))
check_for_dict_arg(argvars, 1) == FAIL)))
return; return;
lnum = tv_get_number(&argvars[0]); lnum = tv_get_number(&argvars[0]);
@ -832,6 +846,14 @@ f_prop_remove(typval_T *argvars, typval_T *rettv)
int both; int both;
rettv->vval.v_number = 0; rettv->vval.v_number = 0;
if (in_vim9script()
&& (check_for_dict_arg(argvars, 0) == FAIL
|| check_for_opt_number_arg(argvars, 1) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
&& check_for_opt_number_arg(argvars, 2) == FAIL)))
return;
if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
{ {
emsg(_(e_invarg)); emsg(_(e_invarg));

View File

@ -270,8 +270,7 @@ f_strftime(typval_T *argvars, typval_T *rettv)
if (in_vim9script() if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL && (check_for_string_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN || check_for_opt_number_arg(argvars, 1) == FAIL))
&& check_for_number_arg(argvars, 1) == FAIL)))
return; return;
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
@ -777,12 +776,17 @@ f_timer_info(typval_T *argvars, typval_T *rettv)
f_timer_pause(typval_T *argvars, typval_T *rettv UNUSED) f_timer_pause(typval_T *argvars, typval_T *rettv UNUSED)
{ {
timer_T *timer = NULL; timer_T *timer = NULL;
int paused = (int)tv_get_bool(&argvars[1]);
if (in_vim9script()
&& (check_for_number_arg(argvars, 0) == FAIL
|| check_for_bool_arg(argvars, 1) == FAIL))
return;
if (argvars[0].v_type != VAR_NUMBER) if (argvars[0].v_type != VAR_NUMBER)
emsg(_(e_number_exp)); emsg(_(e_number_exp));
else else
{ {
int paused = (int)tv_get_bool(&argvars[1]);
timer = find_timer((int)tv_get_number(&argvars[0])); timer = find_timer((int)tv_get_number(&argvars[0]));
if (timer != NULL) if (timer != NULL)
timer->tr_paused = paused; timer->tr_paused = paused;

View File

@ -384,6 +384,16 @@ check_for_nonempty_string_arg(typval_T *args, int idx)
return OK; return OK;
} }
/*
* Check for an optional string argument at 'idx'
*/
int
check_for_opt_string_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_string_arg(args, idx) != FAIL);
}
/* /*
* Give an error and return FAIL unless "args[idx]" is a number. * Give an error and return FAIL unless "args[idx]" is a number.
*/ */
@ -401,6 +411,16 @@ check_for_number_arg(typval_T *args, int idx)
return OK; return OK;
} }
/*
* Check for an optional number argument at 'idx'
*/
int
check_for_opt_number_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_number_arg(args, idx) != FAIL);
}
/* /*
* Give an error and return FAIL unless "args[idx]" is a bool. * Give an error and return FAIL unless "args[idx]" is a bool.
*/ */
@ -421,6 +441,16 @@ check_for_bool_arg(typval_T *args, int idx)
return OK; return OK;
} }
/*
* Check for an optional bool argument at 'idx'
*/
int
check_for_opt_bool_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_bool_arg(args, idx) != FAIL);
}
/* /*
* Give an error and return FAIL unless "args[idx]" is a list. * Give an error and return FAIL unless "args[idx]" is a list.
*/ */
@ -438,6 +468,16 @@ check_for_list_arg(typval_T *args, int idx)
return OK; return OK;
} }
/*
* Check for an optional list argument at 'idx'
*/
int
check_for_opt_list_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_list_arg(args, idx) != FAIL);
}
/* /*
* Give an error and return FAIL unless "args[idx]" is a dict. * Give an error and return FAIL unless "args[idx]" is a dict.
*/ */
@ -455,6 +495,169 @@ check_for_dict_arg(typval_T *args, int idx)
return OK; return OK;
} }
/*
* Check for an optional dict argument at 'idx'
*/
int
check_for_opt_dict_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_dict_arg(args, idx) != FAIL);
}
/*
* Give an error and return FAIL unless "args[idx]" is a blob.
*/
int
check_for_blob_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_BLOB)
{
if (idx >= 0)
semsg(_(e_blob_required_for_argument_nr), idx + 1);
else
emsg(_(e_blobreq));
return FAIL;
}
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a channel or a job.
*/
int
check_for_chan_or_job_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_CHANNEL && args[idx].v_type != VAR_JOB)
{
if (idx >= 0)
semsg(_(e_chan_or_job_required_for_argument_nr), idx + 1);
else
emsg(_(e_chan_or_job_req));
return FAIL;
}
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a job.
*/
int
check_for_job_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_JOB)
{
if (idx >= 0)
semsg(_(e_job_required_for_argument_nr), idx + 1);
else
emsg(_(e_jobreq));
return FAIL;
}
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a number.
*/
int
check_for_string_or_number_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER)
{
if (idx >= 0)
semsg(_(e_string_required_for_argument_nr), idx + 1);
else
emsg(_(e_stringreq));
return FAIL;
}
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a number (buffer)
*/
int
check_for_buffer_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER)
{
if (idx >= 0)
semsg(_(e_string_required_for_argument_nr), idx + 1);
else
emsg(_(e_stringreq));
return FAIL;
}
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a number (line)
*/
int
check_for_lnum_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_NUMBER)
{
if (idx >= 0)
semsg(_(e_string_required_for_argument_nr), idx + 1);
else
emsg(_(e_stringreq));
return FAIL;
}
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a number (line)
*/
int
check_for_opt_lnum_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_UNKNOWN
&& args[idx].v_type != VAR_STRING
&& args[idx].v_type != VAR_NUMBER)
{
if (idx >= 0)
semsg(_(e_string_required_for_argument_nr), idx + 1);
else
emsg(_(e_stringreq));
return FAIL;
}
return OK;
}
/*
* Check for an optional string or number argument at 'idx'
*/
int
check_for_opt_string_or_number_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_string_or_number_arg(args, idx) != FAIL);
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a blob.
*/
int
check_for_string_or_blob_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_BLOB)
{
if (idx >= 0)
semsg(_(e_string_required_for_argument_nr), idx + 1);
else
emsg(_(e_stringreq));
return FAIL;
}
return OK;
}
/* /*
* Get the string value of a variable. * Get the string value of a variable.
* If it is a Number variable, the number is converted into a string. * If it is a Number variable, the number is converted into a string.

View File

@ -755,6 +755,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 */
/**/
3188,
/**/ /**/
3187, 3187,
/**/ /**/