patch 8.2.1685: Vim9: cannot declare a constant value
Problem: Vim9: cannot declare a constant value.
Solution: Introduce ":const!".
diff --git a/src/vim9compile.c b/src/vim9compile.c
index dd3eff4..103e696 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1109,6 +1109,20 @@
}
/*
+ * Generate an ISN_LOCKCONST instruction.
+ */
+ static int
+generate_LOCKCONST(cctx_T *cctx)
+{
+ isn_T *isn;
+
+ RETURN_OK_IF_SKIP(cctx);
+ if ((isn = generate_instr(cctx, ISN_LOCKCONST)) == NULL)
+ return FAIL;
+ return OK;
+}
+
+/*
* Generate an ISN_LOADS instruction.
*/
static int
@@ -4342,7 +4356,7 @@
ufunc_T *ufunc;
int r;
- if (*name_start == '!')
+ if (eap->forceit)
{
emsg(_(e_cannot_use_bang_with_nested_def));
return NULL;
@@ -5232,6 +5246,11 @@
}
else
{
+ if (is_decl && eap->forceit && cmdidx == CMD_const
+ && (dest == dest_script || dest == dest_local))
+ // ":const! var": lock the value, but not referenced variables
+ generate_LOCKCONST(cctx);
+
switch (dest)
{
case dest_option:
@@ -6362,13 +6381,8 @@
char_u *line = arg;
linenr_T lnum;
char *errormsg;
- int above = FALSE;
+ int above = eap->forceit;
- if (*arg == '!')
- {
- above = TRUE;
- line = skipwhite(arg + 1);
- }
eap->regname = *line;
if (eap->regname == '=')
@@ -6411,7 +6425,7 @@
if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
{
- long argt = excmd_get_argt(eap->cmdidx);
+ long argt = eap->argt;
int usefilter = FALSE;
has_expr = argt & (EX_XFILE | EX_EXPAND);
@@ -6870,8 +6884,6 @@
}
}
- p = skipwhite(p);
-
if (cctx.ctx_had_return
&& ea.cmdidx != CMD_elseif
&& ea.cmdidx != CMD_else
@@ -6886,6 +6898,18 @@
goto erret;
}
+ p = skipwhite(p);
+ if (ea.cmdidx != CMD_SIZE
+ && ea.cmdidx != CMD_write && ea.cmdidx != CMD_read)
+ {
+ ea.argt = excmd_get_argt(ea.cmdidx);
+ if ((ea.argt & EX_BANG) && *p == '!')
+ {
+ ea.forceit = TRUE;
+ p = skipwhite(p + 1);
+ }
+ }
+
switch (ea.cmdidx)
{
case CMD_def:
@@ -7309,6 +7333,7 @@
case ISN_LOADTDICT:
case ISN_LOADV:
case ISN_LOADWDICT:
+ case ISN_LOCKCONST:
case ISN_MEMBER:
case ISN_NEGATENR:
case ISN_NEWDICT: