0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.3194: 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, simplify some. (Yegappan
            Lakshmanan, closes #8598)
This commit is contained in:
Yegappan Lakshmanan
2021-07-21 19:09:09 +02:00
committed by Bram Moolenaar
parent 189663bdac
commit cd9172077b
10 changed files with 277 additions and 163 deletions

View File

@@ -575,63 +575,7 @@ check_for_string_or_number_arg(typval_T *args, int idx)
}
/*
* 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'
* Check for an optional string or number argument at 'idx'.
*/
int
check_for_opt_string_or_number_arg(typval_T *args, int idx)
@@ -640,6 +584,46 @@ check_for_opt_string_or_number_arg(typval_T *args, int idx)
|| check_for_string_or_number_arg(args, idx) != FAIL);
}
/*
* Give an error and return FAIL unless "args[idx]" is a buffer number.
* Buffer number can be a number or a string.
*/
int
check_for_buffer_arg(typval_T *args, int idx)
{
return check_for_string_or_number_arg(args, idx);
}
/*
* Check for an optional buffer argument at 'idx'
*/
int
check_for_opt_buffer_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_buffer_arg(args, idx));
}
/*
* Give an error and return FAIL unless "args[idx]" is a line number.
* Line number can be a number or a string.
*/
int
check_for_lnum_arg(typval_T *args, int idx)
{
return check_for_string_or_number_arg(args, idx);
}
/*
* Check for an optional line number argument at 'idx'
*/
int
check_for_opt_lnum_arg(typval_T *args, int idx)
{
return (args[idx].v_type == VAR_UNKNOWN
|| check_for_lnum_arg(args, idx));
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a blob.
@@ -658,6 +642,44 @@ check_for_string_or_blob_arg(typval_T *args, int idx)
return OK;
}
/*
* Give an error and return FAIL unless "args[idx]" is a string or
* a list.
*/
int
check_for_string_or_list_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_STRING && args[idx].v_type != VAR_LIST)
{
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 buffer
* number or a dict.
*/
int
check_for_buffer_or_dict_arg(typval_T *args, int idx)
{
if (args[idx].v_type != VAR_STRING
&& args[idx].v_type != VAR_NUMBER
&& args[idx].v_type != VAR_DICT)
{
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.
* If it is a Number variable, the number is converted into a string.