0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.2.4682: Vim9: can use :unlockvar for const variable

Problem:    Vim9: can use :unlockvar for const variable. (Ernie Rael)
Solution:   Check whether the variable is a const.
This commit is contained in:
Bram Moolenaar
2022-04-04 14:58:06 +01:00
parent 15f74fab65
commit 7a411a306f
8 changed files with 62 additions and 23 deletions

View File

@@ -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)
{