changeset 27398:472bb63632bd v8.2.4227

patch 8.2.4227: Vim9: using "lockvar!" in :def function does not work Commit: https://github.com/vim/vim/commit/e939f5ebbae8dd7825d62d84e0c9910fa1756a9c Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 26 21:32:59 2022 +0000 patch 8.2.4227: Vim9: using "lockvar!" in :def function does not work Problem: Vim9: using "lockvar!" in :def function does not work. Solution: Add "!" instead of "-1". (closes https://github.com/vim/vim/issues/9634)
author Bram Moolenaar <Bram@vim.org>
date Wed, 26 Jan 2022 22:45:04 +0100
parents 48efff3a6f0b
children 53c64ca1c4f3
files src/testdir/test_vim9_cmd.vim src/version.c src/vim9cmds.c
diffstat 3 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -1425,6 +1425,17 @@ def Test_lockvar()
   assert_equal([0, 1, 2], g:therange)
   unlet g:therange
 
+  # use exclamation mark for locking deeper
+  g:nestedlist = [1, [2, 3], 4]
+  lockvar! g:nestedlist
+  try
+    g:nestedlist[1][0] = 9
+  catch /E1119:/
+    caught = true
+  endtry
+  assert_true(caught)
+  unlet g:nestedlist
+
   var d = {a: 1, b: 2}
   d.a = 3
   d.b = 4
--- 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 */
 /**/
+    4227,
+/**/
     4226,
 /**/
     4225,
--- a/src/vim9cmds.c
+++ b/src/vim9cmds.c
@@ -223,10 +223,12 @@ compile_lock_unlock(
 	ret = FAIL;
     else
     {
-	vim_snprintf((char *)buf, len, "%s %d %s",
-		eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar",
-		deep,
-		p);
+	char *cmd = eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar";
+
+	if (deep < 0)
+	    vim_snprintf((char *)buf, len, "%s! %s", cmd, p);
+	else
+	    vim_snprintf((char *)buf, len, "%s %d %s", cmd, deep, p);
 	ret = generate_EXEC_copy(cctx, isn, buf);
 
 	vim_free(buf);