aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/testdir/test_const.vim12
2 files changed, 9 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index b37fd85659..8e3109b8be 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -9045,7 +9045,7 @@ static void set_var_const(const char *name, const size_t name_len,
}
if (is_const) {
- v->di_tv.v_lock |= VAR_LOCKED;
+ tv_item_lock(&v->di_tv, 1, true);
}
}
diff --git a/src/nvim/testdir/test_const.vim b/src/nvim/testdir/test_const.vim
index eaf200e9bb..fc7ea71f6e 100644
--- a/src/nvim/testdir/test_const.vim
+++ b/src/nvim/testdir/test_const.vim
@@ -36,6 +36,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:')
@@ -247,11 +248,14 @@ 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