summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-03-04 12:38:21 +0100
committerBram Moolenaar <Bram@vim.org>2021-03-04 12:38:21 +0100
commit6c3843ca8ab105bfb85f6ea8bcec2cbc03f46e7f (patch)
tree8a465281d263c75273b02673e15ecec42e797bdd
parent2e2d758902dc08a0e383fe6b198e11dd14f1bdf8 (diff)
patch 8.2.2567: Vim9: no error if variable is defined for existing functionv8.2.2567
Problem: Vim9: no error if variable is defined for existing function. Solution: Check if name isn't already in use. (closes #7897)
-rw-r--r--src/evalvars.c11
-rw-r--r--src/testdir/test_vim9_script.vim11
-rw-r--r--src/version.c2
3 files changed, 23 insertions, 1 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index d95118b339..22d39a72f6 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -909,7 +909,7 @@ ex_let(exarg_T *eap)
}
/*
- * Assign the typevalue "tv" to the variable or variables at "arg_start".
+ * Assign the typeval "tv" to the variable or variables at "arg_start".
* Handles both "var" with any type and "[var, var; var]" with a list type.
* When "op" is not NULL it points to a string with characters that
* must appear after the variable(s). Use "+", "-" or "." for add, subtract
@@ -3179,6 +3179,7 @@ set_var_const(
if (di != NULL)
{
+ // Item already exists. Allowed to replace when reloading.
if ((di->di_flags & DI_FLAGS_RELOAD) == 0)
{
if (flags & (ASSIGN_CONST | ASSIGN_FINAL))
@@ -3269,6 +3270,14 @@ set_var_const(
}
else
{
+ // Item not found, check if a function already exists.
+ if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0
+ && lookup_scriptitem(name, STRLEN(name), NULL) == OK)
+ {
+ semsg(_(e_redefining_script_item_str), name);
+ goto failed;
+ }
+
// add a new variable
if (vim9script && is_script_local && (flags & ASSIGN_NO_DECL))
{
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 5d1e4015ad..2743668ee5 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -1515,6 +1515,17 @@ def Test_script_reload_change_type()
delete('Xreload.vim')
enddef
+def Test_script_var_shadows_function()
+ var lines =<< trim END
+ vim9script
+ def Func(): number
+ return 123
+ enddef
+ var Func = 1
+ END
+ CheckScriptFailure(lines, 'E1041:', 5)
+enddef
+
def s:RetSome(): string
return 'some'
enddef
diff --git a/src/version.c b/src/version.c
index c6913d6aed..879931da51 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2567,
+/**/
2566,
/**/
2565,