patch 8.2.1682: Vim9: const works in an unexpected way
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.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 8a46b2f..dd3eff4 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4800,11 +4800,6 @@
semsg(_(e_variable_already_declared), name);
goto theend;
}
- else if (lvar->lv_const)
- {
- semsg(_(e_cannot_assign_to_constant), name);
- goto theend;
- }
}
else
{
@@ -4960,6 +4955,11 @@
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)
{