]> granicus.if.org Git - vim/commitdiff
patch 8.2.2921: E704 for script local variable is not backwards compatible v8.2.2921
authorBram Moolenaar <Bram@vim.org>
Wed, 2 Jun 2021 09:49:23 +0000 (11:49 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 2 Jun 2021 09:49:23 +0000 (11:49 +0200)
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.

src/dict.c
src/testdir/test_functions.vim
src/version.c

index 876eeea4928cb3b3e2a21ebca40fc3cc6c91c6a8..f0f045b27288755ca7961c8e9cef6785f6009f10 100644 (file)
@@ -352,8 +352,9 @@ dict_copy(dict_T *orig, int deep, int copyID)
 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);
 }
index f945e9064e9d6e3887a0a69df8cc4086e8205ffb..bc964917263de9f535855eba94491ea814f868cb 100644 (file)
@@ -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
index 1c01adb222f4038503e157735e2b073a921d99fc..321047f56b7dc3e6e6275d2074254feac99c2d8e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2921,
 /**/
     2920,
 /**/