Skip to content

Commit b4893b8

Browse files
committed
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)
1 parent 7e82c5f commit b4893b8

5 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/proto/vim9compile.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* vim9compile.c */
2+
int script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx);
23
int check_defined(char_u *p, size_t len, cctx_T *cctx);
34
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
45
int use_typecheck(type_T *actual, type_T *expected);

src/testdir/test_vim9_func.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,15 @@ def Test_call_wrong_args()
589589
END
590590
CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got list<unknown>', 5)
591591

592+
lines =<< trim END
593+
vim9script
594+
var name = 'piet'
595+
def FuncOne(name: string)
596+
echo nr
597+
enddef
598+
END
599+
CheckScriptFailure(lines, 'E1054:')
600+
592601
lines =<< trim END
593602
vim9script
594603
def FuncOne(nr: number)

src/userfunc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ one_function_arg(
8080
semsg(_("E125: Illegal argument: %s"), arg);
8181
return arg;
8282
}
83+
84+
// Vim9 script: cannot use script var name for argument.
85+
if (argtypes != NULL && script_var_exists(arg, p - arg, FALSE, NULL) == OK)
86+
{
87+
semsg(_(e_variable_already_declared_in_script), arg);
88+
return arg;
89+
}
90+
8391
if (newargs != NULL && ga_grow(newargs, 1) == FAIL)
8492
return arg;
8593
if (newargs != NULL)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2540,
753755
/**/
754756
2539,
755757
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ script_is_vim9()
337337
* "cctx" is NULL at the script level.
338338
* Returns OK or FAIL.
339339
*/
340-
static int
340+
int
341341
script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
342342
{
343343
int is_vim9_script;

0 commit comments

Comments
 (0)