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)
}
is_script_local = ht == get_script_local_ht();
- if (in_vim9script()
+ if (vim9script
&& !is_script_local
&& (flags & LET_NO_COMMAND) == 0
&& name[1] == ':')
goto failed;
}
- if (is_script_local && in_vim9script())
+ if (is_script_local && vim9script)
{
if ((flags & LET_NO_COMMAND) == 0)
{
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);
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.
def Test_const()
CheckDefFailure(['const var = 234', 'var = 99'], 'E1018:')
CheckDefFailure(['const one = 234', 'let one = 99'], 'E1017:')
+ CheckDefFailure(['const list = [1, 2]', 'let list = [3, 4]'], 'E1017:')
CheckDefFailure(['const two'], 'E1021:')
CheckDefFailure(['const &option'], 'E996:')
+
+ let lines =<< trim END
+ const list = [1, 2, 3]
+ list[0] = 4
+ END
+ CheckDefAndScriptSuccess(lines)
enddef
def Test_range_no_colon()
semsg(_(e_variable_already_declared), name);
goto theend;
}
- else if (lvar->lv_const)
- {
- semsg(_(e_cannot_assign_to_constant), name);
- goto theend;
- }
}
else
{
semsg(_(e_cannot_assign_to_argument), name);
goto theend;
}
+ if (!is_decl && lvar != NULL && lvar->lv_const && !has_index)
+ {
+ semsg(_(e_cannot_assign_to_constant), name);
+ goto theend;
+ }
if (!heredoc)
{