forked from aniani/vim
patch 8.2.0570: Vim9: no error when omitting type from argument
Problem: Vim9: no error when omitting type from argument. Solution: Enforce specifying argument types.
This commit is contained in:
@@ -2273,8 +2273,11 @@ rewind_conditionals(
|
||||
* ":endfunction" when not after a ":function"
|
||||
*/
|
||||
void
|
||||
ex_endfunction(exarg_T *eap UNUSED)
|
||||
ex_endfunction(exarg_T *eap)
|
||||
{
|
||||
if (eap->cmdidx == CMD_enddef)
|
||||
emsg(_("E193: :enddef not inside a function"));
|
||||
else
|
||||
emsg(_("E193: :endfunction not inside a function"));
|
||||
}
|
||||
|
||||
|
@@ -160,7 +160,7 @@ def Test_disassemble_new()
|
||||
res)
|
||||
enddef
|
||||
|
||||
def FuncWithArg(arg)
|
||||
def FuncWithArg(arg: any)
|
||||
echo arg
|
||||
enddef
|
||||
|
||||
@@ -432,7 +432,7 @@ def Test_disassemble_lambda()
|
||||
instr)
|
||||
enddef
|
||||
|
||||
def AndOr(arg): string
|
||||
def AndOr(arg: any): string
|
||||
if arg == 1 && arg != 2 || arg == 4
|
||||
return 'yes'
|
||||
endif
|
||||
|
@@ -859,11 +859,11 @@ def Test_expr7_negate()
|
||||
assert_equal(88, --nr)
|
||||
enddef
|
||||
|
||||
def Echo(arg): string
|
||||
def Echo(arg: any): string
|
||||
return arg
|
||||
enddef
|
||||
|
||||
def s:EchoArg(arg): string
|
||||
def s:EchoArg(arg: any): string
|
||||
return arg
|
||||
enddef
|
||||
|
||||
@@ -991,6 +991,7 @@ def Test_expr7_trailing()
|
||||
assert_equal(123, d.key)
|
||||
enddef
|
||||
|
||||
|
||||
func Test_expr7_trailing_fails()
|
||||
call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)}'], 'E107')
|
||||
call CheckDefFailureList(['let l = [2]', 'l->{l -> add(l, 8)} ()'], 'E274')
|
||||
|
@@ -250,6 +250,7 @@ enddef
|
||||
def Test_arg_type_wrong()
|
||||
CheckScriptFailure(['def Func3(items: list)', 'echo "a"', 'enddef'], 'E1008: Missing <type>')
|
||||
CheckScriptFailure(['def Func4(...)', 'echo "a"', 'enddef'], 'E1055: Missing name after ...')
|
||||
CheckScriptFailure(['def Func5(items)', 'echo "a"'], 'E1077:')
|
||||
enddef
|
||||
|
||||
def Test_vim9script_call()
|
||||
|
@@ -917,7 +917,7 @@ def Test_for_loop_fails()
|
||||
CheckDefFailure(['for # in range(5)'], 'E690:')
|
||||
CheckDefFailure(['for i In range(5)'], 'E690:')
|
||||
CheckDefFailure(['let x = 5', 'for x in range(5)'], 'E1023:')
|
||||
CheckScriptFailure(['def Func(arg)', 'for arg in range(5)', 'enddef'], 'E1006:')
|
||||
CheckScriptFailure(['def Func(arg: any)', 'for arg in range(5)', 'enddef'], 'E1006:')
|
||||
CheckDefFailure(['for i in "text"'], 'E1024:')
|
||||
CheckDefFailure(['for i in xxx'], 'E1001:')
|
||||
CheckDefFailure(['endfor'], 'E588:')
|
||||
|
@@ -64,7 +64,8 @@ func_tbl_get(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Get one function argument and an optional type: "arg: type".
|
||||
* Get one function argument.
|
||||
* If "argtypes" is not NULL also get the type: "arg: type".
|
||||
* Return a pointer to after the type.
|
||||
* When something is wrong return "arg".
|
||||
*/
|
||||
@@ -72,6 +73,7 @@ func_tbl_get(void)
|
||||
one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
|
||||
{
|
||||
char_u *p = arg;
|
||||
char_u *arg_copy = NULL;
|
||||
|
||||
while (ASCII_ISALNUM(*p) || *p == '_')
|
||||
++p;
|
||||
@@ -87,7 +89,6 @@ one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
|
||||
return arg;
|
||||
if (newargs != NULL)
|
||||
{
|
||||
char_u *arg_copy;
|
||||
int c;
|
||||
int i;
|
||||
|
||||
@@ -119,14 +120,24 @@ one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
|
||||
{
|
||||
char_u *type = NULL;
|
||||
|
||||
if (VIM_ISWHITE(*p) && *skipwhite(p) == ':')
|
||||
{
|
||||
semsg(_("E1059: No white space allowed before colon: %s"),
|
||||
arg_copy == NULL ? arg : arg_copy);
|
||||
p = skipwhite(p);
|
||||
}
|
||||
if (*p == ':')
|
||||
{
|
||||
type = skipwhite(p + 1);
|
||||
p = skip_type(type);
|
||||
type = vim_strnsave(type, p - type);
|
||||
}
|
||||
else if (*skipwhite(p) == ':')
|
||||
emsg(_("E1059: No white space allowed before :"));
|
||||
else if (*skipwhite(p) != '=')
|
||||
{
|
||||
semsg(_("E1077: Missing argument type for %s"),
|
||||
arg_copy == NULL ? arg : arg_copy);
|
||||
return arg;
|
||||
}
|
||||
((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type;
|
||||
}
|
||||
|
||||
|
@@ -738,6 +738,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
570,
|
||||
/**/
|
||||
569,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user