1
0
forked from aniani/vim

patch 8.2.2540: Vim9: no error for using script var name for argument

Problem:    Vim9: no error for using script var name for argument.
Solution:   Check for this error. (closes #7868)
This commit is contained in:
Bram Moolenaar 2021-02-21 22:20:24 +01:00
parent 7e82c5f338
commit b4893b8450
5 changed files with 21 additions and 1 deletions

View File

@ -1,4 +1,5 @@
/* vim9compile.c */
int script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx);
int check_defined(char_u *p, size_t len, cctx_T *cctx);
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
int use_typecheck(type_T *actual, type_T *expected);

View File

@ -589,6 +589,15 @@ def Test_call_wrong_args()
END
CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 5)
lines =<< trim END
vim9script
var name = 'piet'
def FuncOne(name: string)
echo nr
enddef
END
CheckScriptFailure(lines, 'E1054:')
lines =<< trim END
vim9script
def FuncOne(nr: number)

View File

@ -80,6 +80,14 @@ one_function_arg(
semsg(_("E125: Illegal argument: %s"), arg);
return arg;
}
// Vim9 script: cannot use script var name for argument.
if (argtypes != NULL && script_var_exists(arg, p - arg, FALSE, NULL) == OK)
{
semsg(_(e_variable_already_declared_in_script), arg);
return arg;
}
if (newargs != NULL && ga_grow(newargs, 1) == FAIL)
return arg;
if (newargs != NULL)

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2540,
/**/
2539,
/**/

View File

@ -337,7 +337,7 @@ script_is_vim9()
* "cctx" is NULL at the script level.
* Returns OK or FAIL.
*/
static int
int
script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
{
int is_vim9_script;