To: vim_dev@googlegroups.com Subject: Patch 8.2.2567 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2567 Problem: Vim9: no error if variable is defined for existing function. Solution: Check if name isn't already in use. (closes #7897) Files: src/evalvars.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.2566/src/evalvars.c 2021-03-03 21:22:37.178739531 +0100 --- src/evalvars.c 2021-03-04 12:25:17.201234437 +0100 *************** *** 909,915 **** } /* ! * Assign the typevalue "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 --- 909,915 ---- } /* ! * 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,3184 **** --- 3179,3185 ---- 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,3274 **** --- 3270,3283 ---- } 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)) { *** ../vim-8.2.2566/src/testdir/test_vim9_script.vim 2021-02-28 16:55:07.513026844 +0100 --- src/testdir/test_vim9_script.vim 2021-03-04 12:36:46.027661064 +0100 *************** *** 1515,1520 **** --- 1515,1531 ---- 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 *** ../vim-8.2.2566/src/version.c 2021-03-03 21:22:37.182739527 +0100 --- src/version.c 2021-03-03 22:24:44.507206111 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2567, /**/ -- NEIL INNES PLAYED: THE FIRST SELF-DESTRUCTIVE MONK, ROBIN'S LEAST FAVORITE MINSTREL, THE PAGE CRUSHED BY A RABBIT, THE OWNER OF A DUCK "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///