forked from aniani/vim
patch 8.2.3904: Vim9: skip expression type is not checked at compile time
Problem: Vim9: skip expression type is not checked at compile time. Solution: Add argument type checks.
This commit is contained in:
@@ -532,6 +532,26 @@ arg_map_func(type_T *type, argcontext_T *context)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check an expression argument, can be a string, funcref or partial.
|
||||||
|
* Also accept a bool, a constant resulting from compiling a string argument.
|
||||||
|
* Also accept a number, one and zero are accepted.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
arg_string_or_func(type_T *type, argcontext_T *context)
|
||||||
|
{
|
||||||
|
if (type->tt_type == VAR_ANY
|
||||||
|
|| type->tt_type == VAR_UNKNOWN
|
||||||
|
|| type->tt_type == VAR_STRING
|
||||||
|
|| type->tt_type == VAR_PARTIAL
|
||||||
|
|| type->tt_type == VAR_FUNC
|
||||||
|
|| type->tt_type == VAR_BOOL
|
||||||
|
|| type->tt_type == VAR_NUMBER)
|
||||||
|
return OK;
|
||||||
|
arg_type_mismatch(&t_func_any, type, context->arg_idx + 1);
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check "type" is a list of 'any' or a blob or a string.
|
* Check "type" is a list of 'any' or a blob or a string.
|
||||||
*/
|
*/
|
||||||
@@ -916,8 +936,8 @@ static argcheck_T arg23_reduce[] = {arg_string_list_or_blob, NULL, NULL};
|
|||||||
static argcheck_T arg24_remote_expr[] = {arg_string, arg_string, arg_string, arg_number};
|
static argcheck_T arg24_remote_expr[] = {arg_string, arg_string, arg_string, arg_number};
|
||||||
static argcheck_T arg23_remove[] = {arg_list_or_dict_or_blob, arg_remove2, arg_number};
|
static argcheck_T arg23_remove[] = {arg_list_or_dict_or_blob, arg_remove2, arg_number};
|
||||||
static argcheck_T arg2_repeat[] = {arg_repeat1, arg_number};
|
static argcheck_T arg2_repeat[] = {arg_repeat1, arg_number};
|
||||||
static argcheck_T arg15_search[] = {arg_string, arg_string, arg_number, arg_number, NULL};
|
static argcheck_T arg15_search[] = {arg_string, arg_string, arg_number, arg_number, arg_string_or_func};
|
||||||
static argcheck_T arg37_searchpair[] = {arg_string, arg_string, arg_string, arg_string, NULL, arg_number, arg_number};
|
static argcheck_T arg37_searchpair[] = {arg_string, arg_string, arg_string, arg_string, arg_string_or_func, arg_number, arg_number};
|
||||||
static argcheck_T arg3_setbufline[] = {arg_buffer, arg_lnum, arg_str_or_nr_or_list};
|
static argcheck_T arg3_setbufline[] = {arg_buffer, arg_lnum, arg_str_or_nr_or_list};
|
||||||
static argcheck_T arg2_setline[] = {arg_lnum, NULL};
|
static argcheck_T arg2_setline[] = {arg_lnum, NULL};
|
||||||
static argcheck_T arg24_setloclist[] = {arg_number, arg_list_any, arg_string, arg_dict_any};
|
static argcheck_T arg24_setloclist[] = {arg_number, arg_list_any, arg_string, arg_dict_any};
|
||||||
|
|||||||
@@ -3007,6 +3007,10 @@ def Test_search()
|
|||||||
CheckDefAndScriptFailure(['search("a", 2)'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
|
CheckDefAndScriptFailure(['search("a", 2)'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
|
||||||
CheckDefAndScriptFailure(['search("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
|
CheckDefAndScriptFailure(['search("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
|
||||||
CheckDefAndScriptFailure(['search("a", "b", 3, "d")'], ['E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4'])
|
CheckDefAndScriptFailure(['search("a", "b", 3, "d")'], ['E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4'])
|
||||||
|
new
|
||||||
|
setline(1, "match this")
|
||||||
|
CheckDefAndScriptFailure(['search("a", "", 9, 0, [0])'], ['E1013: Argument 5: type mismatch, expected func(...): any but got list<number>', 'E730: Using a List as a String'])
|
||||||
|
bwipe!
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_searchcount()
|
def Test_searchcount()
|
||||||
@@ -3058,9 +3062,12 @@ def Test_searchpair()
|
|||||||
vim9script
|
vim9script
|
||||||
setline(1, '()')
|
setline(1, '()')
|
||||||
normal gg
|
normal gg
|
||||||
|
func RetList()
|
||||||
|
return [0]
|
||||||
|
endfunc
|
||||||
def Fail()
|
def Fail()
|
||||||
try
|
try
|
||||||
searchpairpos('(', '', ')', 'nW', '[0]->map("")')
|
searchpairpos('(', '', ')', 'nW', 'RetList()')
|
||||||
catch
|
catch
|
||||||
g:caught = 'yes'
|
g:caught = 'yes'
|
||||||
endtry
|
endtry
|
||||||
@@ -3077,12 +3084,35 @@ def Test_searchpair()
|
|||||||
END
|
END
|
||||||
CheckDefAndScriptFailure(lines, ['E1001: Variable not found: f', 'E475: Invalid argument: d'])
|
CheckDefAndScriptFailure(lines, ['E1001: Variable not found: f', 'E475: Invalid argument: d'])
|
||||||
|
|
||||||
CheckDefAndScriptFailure(['searchpair(1, "b", "c")'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
|
var errors = ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1']
|
||||||
CheckDefAndScriptFailure(['searchpair("a", 2, "c")'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
|
CheckDefAndScriptFailure(['searchpair(1, "b", "c")'], errors)
|
||||||
CheckDefAndScriptFailure(['searchpair("a", "b", 3)'], ['E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3'])
|
CheckDefAndScriptFailure(['searchpairpos(1, "b", "c")'], errors)
|
||||||
CheckDefAndScriptFailure(['searchpair("a", "b", "c", 4)'], ['E1013: Argument 4: type mismatch, expected string but got number', 'E1174: String required for argument 4'])
|
|
||||||
CheckDefAndScriptFailure(['searchpair("a", "b", "c", "r", "1", "f")'], ['E1013: Argument 6: type mismatch, expected number but got string', 'E1210: Number required for argument 6'])
|
errors = ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2']
|
||||||
CheckDefAndScriptFailure(['searchpair("a", "b", "c", "r", "1", 3, "g")'], ['E1013: Argument 7: type mismatch, expected number but got string', 'E1210: Number required for argument 7'])
|
CheckDefAndScriptFailure(['searchpair("a", 2, "c")'], errors)
|
||||||
|
CheckDefAndScriptFailure(['searchpairpos("a", 2, "c")'], errors)
|
||||||
|
|
||||||
|
errors = ['E1013: Argument 3: type mismatch, expected string but got number', 'E1174: String required for argument 3']
|
||||||
|
CheckDefAndScriptFailure(['searchpair("a", "b", 3)'], errors)
|
||||||
|
CheckDefAndScriptFailure(['searchpairpos("a", "b", 3)'], errors)
|
||||||
|
|
||||||
|
errors = ['E1013: Argument 4: type mismatch, expected string but got number', 'E1174: String required for argument 4']
|
||||||
|
CheckDefAndScriptFailure(['searchpair("a", "b", "c", 4)'], errors)
|
||||||
|
|
||||||
|
new
|
||||||
|
setline(1, "match this")
|
||||||
|
errors = ['E1013: Argument 5: type mismatch, expected func(...): any but got list<number>', 'E730: Using a List as a String']
|
||||||
|
CheckDefAndScriptFailure(['searchpair("a", "b", "c", "r", [0])'], errors)
|
||||||
|
CheckDefAndScriptFailure(['searchpairpos("a", "b", "c", "r", [0])'], errors)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
errors = ['E1013: Argument 6: type mismatch, expected number but got string', 'E1210: Number required for argument 6']
|
||||||
|
CheckDefAndScriptFailure(['searchpair("a", "b", "c", "r", "1", "f")'], errors)
|
||||||
|
CheckDefAndScriptFailure(['searchpairpos("a", "b", "c", "r", "1", "f")'], errors)
|
||||||
|
|
||||||
|
errors = ['E1013: Argument 7: type mismatch, expected number but got string', 'E1210: Number required for argument 7']
|
||||||
|
CheckDefAndScriptFailure(['searchpair("a", "b", "c", "r", "1", 3, "g")'], errors)
|
||||||
|
CheckDefAndScriptFailure(['searchpairpos("a", "b", "c", "r", "1", 3, "g")'], errors)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_searchpos()
|
def Test_searchpos()
|
||||||
@@ -3090,6 +3120,10 @@ def Test_searchpos()
|
|||||||
CheckDefAndScriptFailure(['searchpos("a", 2)'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
|
CheckDefAndScriptFailure(['searchpos("a", 2)'], ['E1013: Argument 2: type mismatch, expected string but got number', 'E1174: String required for argument 2'])
|
||||||
CheckDefAndScriptFailure(['searchpos("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
|
CheckDefAndScriptFailure(['searchpos("a", "b", "c")'], ['E1013: Argument 3: type mismatch, expected number but got string', 'E1210: Number required for argument 3'])
|
||||||
CheckDefAndScriptFailure(['searchpos("a", "b", 3, "d")'], ['E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4'])
|
CheckDefAndScriptFailure(['searchpos("a", "b", 3, "d")'], ['E1013: Argument 4: type mismatch, expected number but got string', 'E1210: Number required for argument 4'])
|
||||||
|
new
|
||||||
|
setline(1, "match this")
|
||||||
|
CheckDefAndScriptFailure(['searchpos("a", "", 9, 0, [0])'], ['E1013: Argument 5: type mismatch, expected func(...): any but got list<number>', 'E730: Using a List as a String'])
|
||||||
|
bwipe!
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_server2client()
|
def Test_server2client()
|
||||||
|
|||||||
@@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3904,
|
||||||
/**/
|
/**/
|
||||||
3903,
|
3903,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user