]> granicus.if.org Git - vim/commitdiff
patch 8.2.3651: Vim9: no error for :lock or :unlock with unknown variable v8.2.3651
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Nov 2021 21:58:41 +0000 (21:58 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Nov 2021 21:58:41 +0000 (21:58 +0000)
Problem:    Vim9: no error for :lock or :unlock with unknown variable.
Solution:   Give an error. (closes #9188)

src/errors.h
src/evalvars.c
src/testdir/test_vim9_cmd.vim
src/version.c

index 753e2fe41e9ecdb0912569ecb48bcf0461ba7586..cde98461ec2deed0c70487192f77beb3ac2a0953 100644 (file)
@@ -686,3 +686,5 @@ EXTERN char e_bad_color_string_str[]
        INIT(= N_("E1244: Bad color string: %s"));
 EXTERN char e_cannot_expand_sfile_in_vim9_function[]
        INIT(= N_("E1245: Cannot expand <sfile> in a Vim9 function"));
+EXTERN char e_cannot_find_variable_to_unlock_str[]
+       INIT(= N_("E1246: Cannot find variable to (un)lock: %s"));
index b56073453b6f238c202588114d761b59b7f2e646..b1d7b78c8130b2bcb13b7f4da513166cbfbf43bf 100644 (file)
@@ -1827,7 +1827,12 @@ do_lock_var(
            // Normal name or expanded name.
            di = find_var(lp->ll_name, NULL, TRUE);
            if (di == NULL)
+           {
+               if (in_vim9script())
+                   semsg(_(e_cannot_find_variable_to_unlock_str),
+                                                                 lp->ll_name);
                ret = FAIL;
+           }
            else if ((di->di_flags & DI_FLAGS_FIX)
                            && di->di_tv.v_type != VAR_DICT
                            && di->di_tv.v_type != VAR_LIST)
index 31f20cb266f5549b389ef18d5776b6afc1621355..16f5d55d045af4295022559a366b10b35f99c9fd 100644 (file)
@@ -1370,6 +1370,23 @@ def Test_lockvar()
       unlockvar theList
   END
   CheckDefFailure(lines, 'E1178', 2)
+
+  lines =<< trim END
+      vim9script
+      var name = 'john'
+      lockvar nameX
+  END
+  CheckScriptFailure(lines, 'E1246', 3)
+
+  lines =<< trim END
+      vim9script
+      var name = 'john'
+      def LockIt()
+        lockvar nameX
+      enddef
+      LockIt()
+  END
+  CheckScriptFailure(lines, 'E1246', 1)
 enddef
 
 def Test_substitute_expr()
index 121ce6eae9ba3aff3f8cea54c69372e9a8c76b65..f2bcb190f3dd042c14cd9d5420f7e6fa0470cebe 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3651,
 /**/
     3650,
 /**/