Skip to content

Commit e7877fe

Browse files
committed
patch 8.0.0343: b:changedtick can be unlocked
Problem: b:changedtick can be unlocked, even though it has no effect. (Nikolai Pavlov) Solution: Add a check and error E940. (closes #1496)
1 parent 6739114 commit e7877fe

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

runtime/doc/eval.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9082,9 +9082,12 @@ This does NOT work: >
90829082
:lockvar v
90839083
:let v = 'asdf' " fails!
90849084
:unlet v
9085-
< *E741*
9085+
< *E741* *E940*
90869086
If you try to change a locked variable you get an
9087-
error message: "E741: Value is locked: {name}"
9087+
error message: "E741: Value is locked: {name}".
9088+
If you try to lock or unlock a built-in variable you
9089+
get an error message: "E940: Cannot lock or unlock
9090+
variable {name}".
90889091

90899092
[depth] is relevant when locking a |List| or
90909093
|Dictionary|. It specifies how deep the locking goes:

src/eval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,12 @@ do_lock_var(
28822882
di = find_var(lp->ll_name, NULL, TRUE);
28832883
if (di == NULL)
28842884
ret = FAIL;
2885+
else if ((di->di_flags & DI_FLAGS_FIX)
2886+
&& di->di_tv.v_type != VAR_DICT
2887+
&& di->di_tv.v_type != VAR_LIST)
2888+
/* For historic reasons this error is not given for a list or dict.
2889+
* E.g., the b: dict could be locked/unlocked. */
2890+
EMSG2(_("E940: Cannot lock or unlock variable %s"), lp->ll_name);
28852891
else
28862892
{
28872893
if (lock)

src/testdir/test_changedtick.vim

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ func Test_changedtick_bdel()
3333
endfunc
3434

3535
func Test_changedtick_fixed()
36-
call assert_fails('let b:changedtick = 4', 'E46')
37-
call assert_fails('let b:["changedtick"] = 4', 'E46')
36+
call assert_fails('let b:changedtick = 4', 'E46:')
37+
call assert_fails('let b:["changedtick"] = 4', 'E46:')
3838

39-
call assert_fails('unlet b:changedtick', 'E795')
40-
call assert_fails('unlet b:["changedtick"]', 'E46')
39+
call assert_fails('lockvar b:changedtick', 'E940:')
40+
call assert_fails('lockvar b:["changedtick"]', 'E46:')
41+
call assert_fails('unlockvar b:changedtick', 'E940:')
42+
call assert_fails('unlockvar b:["changedtick"]', 'E46:')
43+
call assert_fails('unlet b:changedtick', 'E795:')
44+
call assert_fails('unlet b:["changedtick"]', 'E46:')
4145

4246
let d = b:
43-
call assert_fails('unlet d["changedtick"]', 'E46')
47+
call assert_fails('lockvar d["changedtick"]', 'E46:')
48+
call assert_fails('unlockvar d["changedtick"]', 'E46:')
49+
call assert_fails('unlet d["changedtick"]', 'E46:')
4450

4551
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
343,
767769
/**/
768770
342,
769771
/**/

0 commit comments

Comments
 (0)