summaryrefslogtreecommitdiffstats
path: root/src/evalvars.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-04-04 14:58:06 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-04 14:58:06 +0100
commit7a411a306f90339d8686e42ac16e1ae4fc7533c5 (patch)
treedef2607a7145867c305c4d55baf955bc21649bde /src/evalvars.c
parent15f74fab653a784548d5d966644926b47ba2cfa7 (diff)
patch 8.2.4682: Vim9: can use :unlockvar for const variablev8.2.4682
Problem: Vim9: can use :unlockvar for const variable. (Ernie Rael) Solution: Check whether the variable is a const.
Diffstat (limited to 'src/evalvars.c')
-rw-r--r--src/evalvars.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index dd70427d32..c1ec5b0bab 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -1951,23 +1951,42 @@ do_lock_var(
lp->ll_name);
ret = FAIL;
}
- else if ((di->di_flags & DI_FLAGS_FIX)
- && di->di_tv.v_type != VAR_DICT
- && di->di_tv.v_type != VAR_LIST)
- {
- // For historic reasons this error is not given for a list or
- // dict. E.g., the b: dict could be locked/unlocked.
- semsg(_(e_cannot_lock_or_unlock_variable_str), lp->ll_name);
- ret = FAIL;
- }
else
{
- if (lock)
- di->di_flags |= DI_FLAGS_LOCK;
+ if ((di->di_flags & DI_FLAGS_FIX)
+ && di->di_tv.v_type != VAR_DICT
+ && di->di_tv.v_type != VAR_LIST)
+ {
+ // For historic reasons this error is not given for a list
+ // or dict. E.g., the b: dict could be locked/unlocked.
+ semsg(_(e_cannot_lock_or_unlock_variable_str), lp->ll_name);
+ ret = FAIL;
+ }
else
- di->di_flags &= ~DI_FLAGS_LOCK;
- if (deep != 0)
- item_lock(&di->di_tv, deep, lock, FALSE);
+ {
+ if (in_vim9script())
+ {
+ svar_T *sv = find_typval_in_script(&di->di_tv,
+ 0, FALSE);
+
+ if (sv != NULL && sv->sv_const != 0)
+ {
+ semsg(_(e_cannot_change_readonly_variable_str),
+ lp->ll_name);
+ ret = FAIL;
+ }
+ }
+
+ if (ret == OK)
+ {
+ if (lock)
+ di->di_flags |= DI_FLAGS_LOCK;
+ else
+ di->di_flags &= ~DI_FLAGS_LOCK;
+ if (deep != 0)
+ item_lock(&di->di_tv, deep, lock, FALSE);
+ }
+ }
}
}
*name_end = cc;
@@ -2812,7 +2831,7 @@ eval_variable(
if (ht != NULL && ht == get_script_local_ht()
&& tv != &SCRIPT_SV(current_sctx.sc_sid)->sv_var.di_tv)
{
- svar_T *sv = find_typval_in_script(tv, 0);
+ svar_T *sv = find_typval_in_script(tv, 0, TRUE);
if (sv != NULL)
type = sv->sv_type;
@@ -3557,7 +3576,7 @@ set_var_const(
if (var_in_vim9script && (flags & ASSIGN_FOR_LOOP) == 0)
{
where_T where = WHERE_INIT;
- svar_T *sv = find_typval_in_script(&di->di_tv, sid);
+ svar_T *sv = find_typval_in_script(&di->di_tv, sid, TRUE);
if (sv != NULL)
{