patch 8.2.2652: Vim9: can use command modifier without an effect
Problem: Vim9: can use command modifier without an effect.
Solution: Give an error for a misplaced command modifier. Fix error message
number.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 41db5e6..c5f0f2a 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -2142,11 +2142,7 @@
{
isn_T *isn;
- if (cmod->cmod_flags != 0
- || cmod->cmod_split != 0
- || cmod->cmod_verbose != 0
- || cmod->cmod_tab != 0
- || cmod->cmod_filter_regmatch.regprog != NULL)
+ if (has_cmdmod(cmod))
{
cctx->ctx_has_cmdmod = TRUE;
@@ -2172,22 +2168,19 @@
return OK;
}
-/*
- * If an ISN_CMDMOD was just generated drop it.
- */
- static void
-drop_cmdmod(cctx_T *cctx)
+ static int
+misplaced_cmdmod(cctx_T *cctx)
{
garray_T *instr = &cctx->ctx_instr;
- // Drop any CMDMOD instruction
if (cctx->ctx_has_cmdmod
&& ((isn_T *)instr->ga_data)[instr->ga_len - 1].isn_type
== ISN_CMDMOD)
{
- --instr->ga_len;
- cctx->ctx_has_cmdmod = FALSE;
+ emsg(_(e_misplaced_command_modifier));
+ return TRUE;
}
+ return FALSE;
}
/*
@@ -7147,7 +7140,9 @@
garray_T *instr = &cctx->ctx_instr;
isn_T *isn;
- drop_cmdmod(cctx);
+ if (misplaced_cmdmod(cctx))
+ return NULL;
+
if (scope == NULL || scope->se_type != IF_SCOPE)
{
emsg(_(e_endif_without_if));
@@ -7393,7 +7388,8 @@
forscope_T *forscope;
isn_T *isn;
- drop_cmdmod(cctx);
+ if (misplaced_cmdmod(cctx))
+ return NULL;
if (scope == NULL || scope->se_type != FOR_SCOPE)
{
@@ -7479,7 +7475,8 @@
scope_T *scope = cctx->ctx_scope;
garray_T *instr = &cctx->ctx_instr;
- drop_cmdmod(cctx);
+ if (misplaced_cmdmod(cctx))
+ return NULL;
if (scope == NULL || scope->se_type != WHILE_SCOPE)
{
emsg(_(e_while));
@@ -7644,6 +7641,9 @@
scope_T *try_scope;
scope_T *scope;
+ if (misplaced_cmdmod(cctx))
+ return NULL;
+
// scope that holds the jumps that go to catch/finally/endtry
try_scope = new_scope(cctx, TRY_SCOPE);
if (try_scope == NULL)
@@ -7684,6 +7684,9 @@
char_u *p;
isn_T *isn;
+ if (misplaced_cmdmod(cctx))
+ return NULL;
+
// end block scope from :try or :catch
if (scope != NULL && scope->se_type == BLOCK_SCOPE)
compile_endblock(cctx);
@@ -7796,6 +7799,9 @@
isn_T *isn;
int this_instr;
+ if (misplaced_cmdmod(cctx))
+ return NULL;
+
// end block scope from :try or :catch
if (scope != NULL && scope->se_type == BLOCK_SCOPE)
compile_endblock(cctx);
@@ -7854,6 +7860,9 @@
garray_T *instr = &cctx->ctx_instr;
isn_T *try_isn;
+ if (misplaced_cmdmod(cctx))
+ return NULL;
+
// end block scope from :catch or :finally
if (scope != NULL && scope->se_type == BLOCK_SCOPE)
compile_endblock(cctx);