# HG changeset patch # User Bram Moolenaar # Date 1622628006 -7200 # Node ID 29ed95687f745c704c2910c5c8d59f1722d0edc6 # Parent 372bdabfca0a25b023e6d51b4ce74c50c202f13c patch 8.2.2921: E704 for script local variable is not backwards compatible Commit: https://github.com/vim/vim/commit/b54abeeafb074248597878a874fed9a66b114c06 Author: Bram Moolenaar Date: Wed Jun 2 11:49:23 2021 +0200 patch 8.2.2921: E704 for script local variable is not backwards compatible Problem: E704 for script local variable is not backwards compatible. (Yasuhiro Matsumoto) Solution: Only give the error in Vim9 script. Also check for function-local variable. diff --git a/src/dict.c b/src/dict.c --- a/src/dict.c +++ b/src/dict.c @@ -352,8 +352,9 @@ dict_copy(dict_T *orig, int deep, int co dict_wrong_func_name(dict_T *d, typval_T *tv, char_u *name) { return (d == get_globvar_dict() - || (SCRIPT_ID_VALID(current_sctx.sc_sid) - && d == &SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict)) + || (in_vim9script() && SCRIPT_ID_VALID(current_sctx.sc_sid) + && d == &SCRIPT_ITEM(current_sctx.sc_sid)->sn_vars->sv_dict) + || &d->dv_hashtab == get_funccal_local_ht()) && (tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL) && var_wrong_func_name(name, TRUE); } diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -4,6 +4,7 @@ source shared.vim source check.vim source term_util.vim source screendump.vim +source vim9.vim " Must be done first, since the alternate buffer must be unset. func Test_00_bufexists() @@ -2684,8 +2685,13 @@ endfunc func Test_builtin_check() call assert_fails('let g:["trim"] = {x -> " " .. x}', 'E704:') call assert_fails('let g:.trim = {x -> " " .. x}', 'E704:') - call assert_fails('let s:["trim"] = {x -> " " .. x}', 'E704:') - call assert_fails('let s:.trim = {x -> " " .. x}', 'E704:') + call assert_fails('let l:["trim"] = {x -> " " .. x}', 'E704:') + call assert_fails('let l:.trim = {x -> " " .. x}', 'E704:') + let lines =<< trim END + vim9script + var s:trim = (x) => " " .. x + END + call CheckScriptFailure(lines, 'E704:') call assert_fails('call extend(g:, #{foo: { -> "foo" }})', 'E704:') let g:bar = 123 diff --git a/src/version.c b/src/version.c --- 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 */ /**/ + 2921, +/**/ 2920, /**/ 2919,