summaryrefslogtreecommitdiffstats
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-14 18:15:09 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-14 18:15:09 +0200
commitdbeecb2b6bc5bf90b7345807e0a313fe890a7c7b (patch)
treeec6d6811457956a75a6deaf63566e0d73690e7ab /src/evalvars.c
parent08052228a72074cdb0165e65f01b2fa8fce867ea (diff)
patch 8.2.1682: Vim9: const works in an unexpected wayv8.2.1682
Problem: Vim9: const works in an unexpected way. Solution: ":const" only disallows changing the variable, not the value. Make "list[0] = 9" work at the script level.
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index f2e875cc8a..bcc425da5a 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -2945,6 +2945,7 @@ set_var_const(
char_u *varname;
hashtab_T *ht;
int is_script_local;
+ int vim9script = in_vim9script();
ht = find_var_ht(name, &varname);
if (ht == NULL || *varname == NUL)
@@ -2954,7 +2955,7 @@ set_var_const(
}
is_script_local = ht == get_script_local_ht();
- if (in_vim9script()
+ if (vim9script
&& !is_script_local
&& (flags & LET_NO_COMMAND) == 0
&& name[1] == ':')
@@ -2992,7 +2993,7 @@ set_var_const(
goto failed;
}
- if (is_script_local && in_vim9script())
+ if (is_script_local && vim9script)
{
if ((flags & LET_NO_COMMAND) == 0)
{
@@ -3088,7 +3089,7 @@ set_var_const(
if (flags & LET_IS_CONST)
di->di_flags |= DI_FLAGS_LOCK;
- if (is_script_local && in_vim9script())
+ if (is_script_local && vim9script)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
@@ -3123,7 +3124,8 @@ set_var_const(
init_tv(tv);
}
- if (flags & LET_IS_CONST)
+ // ":const var = val" locks the value, but not in Vim9 script
+ if ((flags & LET_IS_CONST) && !vim9script)
// Like :lockvar! name: lock the value and what it contains, but only
// if the reference count is up to one. That locks only literal
// values.