diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-08-16 22:50:01 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-08-16 22:50:01 +0200 |
commit | 241572794f7e93d2f8b762de2300e5f7e4f07628 (patch) | |
tree | 86330e27b7484a12b27bbc36062f7a00516f8723 /src | |
parent | c0f8823ee4ca629db5446ba0a935f68d4a4fb193 (diff) | |
download | vim-git-241572794f7e93d2f8b762de2300e5f7e4f07628.tar.gz |
patch 8.2.1471: :const only locks the variable, not the valuev8.2.1471
Problem: :const only locks the variable, not the value.
Solution: Lock the value as ":lockvar 1 var" would do. (closes #6719)
Diffstat (limited to 'src')
-rw-r--r-- | src/evalvars.c | 2 | ||||
-rw-r--r-- | src/testdir/test_const.vim | 12 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 2f4a11b2c..4ebcb4512 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -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); } /* diff --git a/src/testdir/test_const.vim b/src/testdir/test_const.vim index a0f919e45..c993f56a8 100644 --- a/src/testdir/test_const.vim +++ b/src/testdir/test_const.vim @@ -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 diff --git a/src/version.c b/src/version.c index b96a49fff..7e660d8c4 100644 --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1471, +/**/ 1470, /**/ 1469, |