Mercurial > vim
changeset 24051:da8347e453b4 v8.2.2567
patch 8.2.2567: Vim9: no error if variable is defined for existing function
Commit: https://github.com/vim/vim/commit/6c3843ca8ab105bfb85f6ea8bcec2cbc03f46e7f
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 4 12:38:21 2021 +0100
patch 8.2.2567: Vim9: no error if variable is defined for existing function
Problem: Vim9: no error if variable is defined for existing function.
Solution: Check if name isn't already in use. (closes https://github.com/vim/vim/issues/7897)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Mar 2021 12:45:03 +0100 |
parents | df5c5e5bda0c |
children | 56f6a8dddaea |
files | src/evalvars.c src/testdir/test_vim9_script.vim src/version.c |
diffstat | 3 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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)) {
--- 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