diff options
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index dd70427d3..c1ec5b0ba 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) { |