summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-02 14:35:15 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-02 14:35:15 +0200
commitf5906aa7807e9a14159cbc09a141138a2a068ab2 (patch)
treee94aa85babaa4f33d3db4bc623ee966cd241a3f8
parent3fa5e64e0ed55de718e48d0268edc360b2352bc1 (diff)
downloadvim-git-f5906aa7807e9a14159cbc09a141138a2a068ab2.tar.gz
patch 8.2.2692: Vim9: locked script variable can be changedv8.2.2692
Problem: Vim9: locked script variable can be changed. Solution: Check for locked value. (closes #8031)
-rw-r--r--src/testdir/test_vim9_assign.vim11
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c7
3 files changed, 20 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index 41ec7c7be..c06205225 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -1348,6 +1348,17 @@ def Test_var_declaration_fails()
lines =<< trim END
vim9script
+ var name = 'one'
+ lockvar name
+ def SetLocked()
+ name = 'two'
+ enddef
+ SetLocked()
+ END
+ CheckScriptFailure(lines, 'E741: Value is locked: name')
+
+ lines =<< trim END
+ vim9script
def SetGlobalConst()
const g:globConst = 123
enddef
diff --git a/src/version.c b/src/version.c
index 72b798792..105958500 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2692,
+/**/
2691,
/**/
2690,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 9b7f87b6c..69254bebe 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1958,6 +1958,13 @@ call_def_function(
if (sv == NULL)
goto failed;
--ectx.ec_stack.ga_len;
+
+ // "const" and "final" are checked at compile time, locking
+ // the value needs to be checked here.
+ SOURCING_LNUM = iptr->isn_lnum;
+ if (value_check_lock(sv->sv_tv->v_lock, sv->sv_name, FALSE))
+ goto on_error;
+
clear_tv(sv->sv_tv);
*sv->sv_tv = *STACK_TV_BOT(0);
}