]> granicus.if.org Git - vim/commitdiff
patch 8.2.1471: :const only locks the variable, not the value v8.2.1471
authorBram Moolenaar <Bram@vim.org>
Sun, 16 Aug 2020 20:50:01 +0000 (22:50 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 16 Aug 2020 20:50:01 +0000 (22:50 +0200)
Problem:    :const only locks the variable, not the value.
Solution:   Lock the value as ":lockvar 1 var" would do. (closes #6719)

src/evalvars.c
src/testdir/test_const.vim
src/version.c

index 2f4a11b2cc7320a20d7b11294f74c2fde50995ad..4ebcb451295812fd7d1273404e0ccfeeee283423 100644 (file)
@@ -3087,7 +3087,7 @@ set_var_const(
     }
 
     if (flags & LET_IS_CONST)
-       di->di_tv.v_lock |= VAR_LOCKED;
+       item_lock(&di->di_tv, 1, TRUE);
 }
 
 /*
index a0f919e45e823c7b362f550a8e595bfed3fe9bb1..c993f56a8f393da1702a05af49afb46fc887a4d8 100644 (file)
@@ -41,6 +41,7 @@ func Test_define_var_with_lock()
     call assert_fails('let s = "vim"', 'E741:')
     call assert_fails('let F = funcref("s:noop")', 'E741:')
     call assert_fails('let l = [1, 2, 3]', 'E741:')
+    call assert_fails('call filter(l, "v:val % 2 == 0")', 'E741:')
     call assert_fails('let d = {"foo": 10}', 'E741:')
     if has('channel')
       call assert_fails('let j = test_null_job()', 'E741:')
@@ -276,13 +277,16 @@ func Test_lock_depth_is_1()
     const l = [1, 2, 3]
     const d = {'foo': 10}
 
-    " Modify list
-    call add(l, 4)
+    " Modify list - setting item is OK, adding/removing items not
     let l[0] = 42
+    call assert_fails('call add(l, 4)', 'E741:')
+    call assert_fails('unlet l[1]', 'E741:')
 
-    " Modify dict
-    let d['bar'] = 'hello'
+    " Modify dict - changing item is OK, adding/removing items not
+    let d['foo'] = 'hello'
     let d.foo = 44
+    call assert_fails("let d['bar'] = 'hello'", 'E741:')
+    call assert_fails("unlet d['foo']", 'E741:')
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index b96a49fff3a2a9527f98cee4157491b035b5d06c..7e660d8c40cc67e5f94bb2c7dfa57409b978c220 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1471,
 /**/
     1470,
 /**/