0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.4224: Vim9: no error when using a number for map() second argument

Problem:    Vim9: no error when using a number for map() second argument
Solution:   Disallow number to string conversion. (closes #9630)
This commit is contained in:
Bram Moolenaar
2022-01-26 18:26:21 +00:00
parent 1a804528ab
commit 1080c48ec8
4 changed files with 50 additions and 20 deletions

View File

@@ -291,7 +291,7 @@ eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
} }
else else
{ {
s = tv_get_string_buf_chk(expr, buf); s = tv_get_string_buf_chk_strict(expr, buf, TRUE);
if (s == NULL) if (s == NULL)
return FAIL; return FAIL;
s = skipwhite(s); s = skipwhite(s);

View File

@@ -491,8 +491,15 @@ arg_list_or_dict_or_blob_or_string(type_T *type, type_T *decl_type UNUSED, argco
static int static int
arg_filter_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) arg_filter_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
{ {
if (type->tt_type == VAR_FUNC if (type->tt_type == VAR_STRING
&& !(type->tt_member->tt_type == VAR_BOOL || type->tt_type == VAR_PARTIAL
|| type == &t_unknown
|| type == &t_any)
return OK;
if (type->tt_type == VAR_FUNC)
{
if (!(type->tt_member->tt_type == VAR_BOOL
|| type->tt_member->tt_type == VAR_NUMBER || type->tt_member->tt_type == VAR_NUMBER
|| type->tt_member->tt_type == VAR_UNKNOWN || type->tt_member->tt_type == VAR_UNKNOWN
|| type->tt_member->tt_type == VAR_ANY)) || type->tt_member->tt_type == VAR_ANY))
@@ -500,6 +507,12 @@ arg_filter_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
arg_type_mismatch(&t_func_bool, type, context->arg_idx + 1); arg_type_mismatch(&t_func_bool, type, context->arg_idx + 1);
return FAIL; return FAIL;
} }
}
else
{
semsg(_(e_string_or_function_required_for_argument_nr), 2);
return FAIL;
}
return OK; return OK;
} }
@@ -509,8 +522,15 @@ arg_filter_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
static int static int
arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context) arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
{ {
if (type->tt_type == VAR_FUNC if (type->tt_type == VAR_STRING
&& type->tt_member != &t_any || type->tt_type == VAR_PARTIAL
|| type == &t_unknown
|| type == &t_any)
return OK;
if (type->tt_type == VAR_FUNC)
{
if (type->tt_member != &t_any
&& type->tt_member != &t_unknown) && type->tt_member != &t_unknown)
{ {
type_T *expected = NULL; type_T *expected = NULL;
@@ -530,6 +550,12 @@ arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
return check_arg_type(&t_func_exp, type, context); return check_arg_type(&t_func_exp, type, context);
} }
} }
}
else
{
semsg(_(e_string_or_function_required_for_argument_nr), 2);
return FAIL;
}
return OK; return OK;
} }

View File

@@ -1275,6 +1275,7 @@ enddef
def Test_filter() def Test_filter()
CheckDefAndScriptFailure(['filter(1.1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got float', 'E1251: List, Dictionary, Blob or String required for argument 1']) CheckDefAndScriptFailure(['filter(1.1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got float', 'E1251: List, Dictionary, Blob or String required for argument 1'])
CheckDefAndScriptFailure(['filter([1, 2], 4)'], ['E1256: String or function required for argument 2', 'E1024: Using a Number as a String'])
var lines =<< trim END var lines =<< trim END
def F(i: number, v: any): string def F(i: number, v: any): string
@@ -2153,6 +2154,7 @@ def Test_map()
CheckDefAndScriptFailure(['map(test_null_channel(), "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got channel', 'E1251: List, Dictionary, Blob or String required for argument 1']) CheckDefAndScriptFailure(['map(test_null_channel(), "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got channel', 'E1251: List, Dictionary, Blob or String required for argument 1'])
endif endif
CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1251: List, Dictionary, Blob or String required for argument 1']) CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list<any> but got number', 'E1251: List, Dictionary, Blob or String required for argument 1'])
CheckDefAndScriptFailure(['map([1, 2], 4)'], ['E1256: String or function required for argument 2', 'E1024: Using a Number as a String'])
# type of dict remains dict<any> even when type of values changes # type of dict remains dict<any> even when type of values changes
# same for list # same for list

View File

@@ -750,6 +750,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 */
/**/
4224,
/**/ /**/
4223, 4223,
/**/ /**/