]> granicus.if.org Git - vim/commitdiff
patch 8.2.2692: Vim9: locked script variable can be changed v8.2.2692
authorBram Moolenaar <Bram@vim.org>
Fri, 2 Apr 2021 12:35:15 +0000 (14:35 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 2 Apr 2021 12:35:15 +0000 (14:35 +0200)
Problem:    Vim9: locked script variable can be changed.
Solution:   Check for locked value. (closes #8031)

src/testdir/test_vim9_assign.vim
src/version.c
src/vim9execute.c

index 41ec7c7bec0f03e9be7e12109de9f51d6357073f..c06205225d99a97ad136da0f147f2eb185efe58e 100644 (file)
@@ -1346,6 +1346,17 @@ def Test_var_declaration_fails()
   CheckScriptFailure(lines, 'E741:')
   unlet g:constvar
 
+  lines =<< trim END
+    vim9script
+    var name = 'one'
+    lockvar name
+    def SetLocked()
+      name = 'two'
+    enddef
+    SetLocked()
+  END
+  CheckScriptFailure(lines, 'E741: Value is locked: name')
+
   lines =<< trim END
     vim9script
     def SetGlobalConst()
index 72b7987927e17ba0e40f390987b5b652436cd948..1059585008a36e3e5d902752ad24b007c99dcdf8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2692,
 /**/
     2691,
 /**/
index 9b7f87b6c13aade84b98fee9e25fb248eeb83ed9..69254bebeebdfca85f3d90aeadcd33e7f1682304 100644 (file)
@@ -1958,6 +1958,13 @@ call_def_function(
                    if (sv == NULL)
                        goto failed;
                    --ectx.ec_stack.ga_len;
+
+                   // "const" and "final" are checked at compile time, locking
+                   // the value needs to be checked here.
+                   SOURCING_LNUM = iptr->isn_lnum;
+                   if (value_check_lock(sv->sv_tv->v_lock, sv->sv_name, FALSE))
+                       goto on_error;
+
                    clear_tv(sv->sv_tv);
                    *sv->sv_tv = *STACK_TV_BOT(0);
                }