aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt13
-rw-r--r--src/nvim/testdir/test_const.vim24
2 files changed, 30 insertions, 7 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 6649bebedb..a17808e298 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -9631,15 +9631,10 @@ This does NOT work: >
If the system does not support deleting an environment
variable, it is made empty.
- *:cons* *:const* *E996*
+ *:cons* *:const*
:cons[t] {var-name} = {expr1}
:cons[t] [{name1}, {name2}, ...] = {expr1}
-:cons[t] [{name1}, {name2}, ...] .= {expr1}
:cons[t] [{name}, ..., ; {lastname}] = {expr1}
-:cons[t] {var-name} =<< [trim] {marker}
-text...
-text...
-{marker}
Similar to |:let|, but additionally lock the variable
after setting the value. This is the same as locking
the variable with |:lockvar| just after |:let|, thus: >
@@ -9653,7 +9648,11 @@ text...
|:const| does not allow to for changing a variable. >
:let x = 1
:const x = 2 " Error!
-<
+< *E996*
+ Note that environment variables, option values and
+ register values cannot be used here, since they cannot
+ be locked.
+
:lockv[ar][!] [depth] {name} ... *:lockvar* *:lockv*
Lock the internal variable {name}. Locking means that
it can no longer be changed (until it is unlocked).
diff --git a/src/nvim/testdir/test_const.vim b/src/nvim/testdir/test_const.vim
index 641f7cc051..06062c5e58 100644
--- a/src/nvim/testdir/test_const.vim
+++ b/src/nvim/testdir/test_const.vim
@@ -18,6 +18,19 @@ func Test_define_var_with_lock()
const b = v:true
const n = v:null
+ call assert_true(exists('i'))
+ call assert_true(exists('f'))
+ call assert_true(exists('s'))
+ call assert_true(exists('F'))
+ call assert_true(exists('l'))
+ call assert_true(exists('d'))
+ if has('channel')
+ call assert_true(exists('j'))
+ call assert_true(exists('c'))
+ endif
+ call assert_true(exists('b'))
+ call assert_true(exists('n'))
+
call assert_fails('let i = 1', 'E741:')
call assert_fails('let f = 1.1', 'E741:')
call assert_fails('let s = "vim"', 'E741:')
@@ -199,6 +212,17 @@ func Test_const_with_special_variables()
call assert_fails('const &g:encoding = "utf-8"', 'E996:')
endfunc
+func Test_const_with_eval_name()
+ let s = 'foo'
+
+ " eval name with :const should work
+ const abc_{s} = 1
+ const {s}{s} = 1
+
+ let s2 = 'abc_foo'
+ call assert_fails('const {s2} = "bar"', 'E995:')
+endfunc
+
func Test_lock_depth_is_1()
const l = [1, 2, 3]
const d = {'foo': 10}