@@ -2142,11 +2142,7 @@ generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod)
21422142{
21432143 isn_T * isn ;
21442144
2145- if (cmod -> cmod_flags != 0
2146- || cmod -> cmod_split != 0
2147- || cmod -> cmod_verbose != 0
2148- || cmod -> cmod_tab != 0
2149- || cmod -> cmod_filter_regmatch .regprog != NULL )
2145+ if (has_cmdmod (cmod ))
21502146 {
21512147 cctx -> ctx_has_cmdmod = TRUE;
21522148
@@ -2172,22 +2168,19 @@ generate_undo_cmdmods(cctx_T *cctx)
21722168 return OK ;
21732169}
21742170
2175- /*
2176- * If an ISN_CMDMOD was just generated drop it.
2177- */
2178- static void
2179- drop_cmdmod (cctx_T * cctx )
2171+ static int
2172+ misplaced_cmdmod (cctx_T * cctx )
21802173{
21812174 garray_T * instr = & cctx -> ctx_instr ;
21822175
2183- // Drop any CMDMOD instruction
21842176 if (cctx -> ctx_has_cmdmod
21852177 && ((isn_T * )instr -> ga_data )[instr -> ga_len - 1 ].isn_type
21862178 == ISN_CMDMOD )
21872179 {
2188- -- instr -> ga_len ;
2189- cctx -> ctx_has_cmdmod = FALSE ;
2180+ emsg ( _ ( e_misplaced_command_modifier )) ;
2181+ return TRUE ;
21902182 }
2183+ return FALSE;
21912184}
21922185
21932186/*
@@ -7147,7 +7140,9 @@ compile_endif(char_u *arg, cctx_T *cctx)
71477140 garray_T * instr = & cctx -> ctx_instr ;
71487141 isn_T * isn ;
71497142
7150- drop_cmdmod (cctx );
7143+ if (misplaced_cmdmod (cctx ))
7144+ return NULL ;
7145+
71517146 if (scope == NULL || scope -> se_type != IF_SCOPE )
71527147 {
71537148 emsg (_ (e_endif_without_if ));
@@ -7393,7 +7388,8 @@ compile_endfor(char_u *arg, cctx_T *cctx)
73937388 forscope_T * forscope ;
73947389 isn_T * isn ;
73957390
7396- drop_cmdmod (cctx );
7391+ if (misplaced_cmdmod (cctx ))
7392+ return NULL ;
73977393
73987394 if (scope == NULL || scope -> se_type != FOR_SCOPE )
73997395 {
@@ -7479,7 +7475,8 @@ compile_endwhile(char_u *arg, cctx_T *cctx)
74797475 scope_T * scope = cctx -> ctx_scope ;
74807476 garray_T * instr = & cctx -> ctx_instr ;
74817477
7482- drop_cmdmod (cctx );
7478+ if (misplaced_cmdmod (cctx ))
7479+ return NULL ;
74837480 if (scope == NULL || scope -> se_type != WHILE_SCOPE )
74847481 {
74857482 emsg (_ (e_while ));
@@ -7644,6 +7641,9 @@ compile_try(char_u *arg, cctx_T *cctx)
76447641 scope_T * try_scope ;
76457642 scope_T * scope ;
76467643
7644+ if (misplaced_cmdmod (cctx ))
7645+ return NULL ;
7646+
76477647 // scope that holds the jumps that go to catch/finally/endtry
76487648 try_scope = new_scope (cctx , TRY_SCOPE );
76497649 if (try_scope == NULL )
@@ -7684,6 +7684,9 @@ compile_catch(char_u *arg, cctx_T *cctx UNUSED)
76847684 char_u * p ;
76857685 isn_T * isn ;
76867686
7687+ if (misplaced_cmdmod (cctx ))
7688+ return NULL ;
7689+
76877690 // end block scope from :try or :catch
76887691 if (scope != NULL && scope -> se_type == BLOCK_SCOPE )
76897692 compile_endblock (cctx );
@@ -7796,6 +7799,9 @@ compile_finally(char_u *arg, cctx_T *cctx)
77967799 isn_T * isn ;
77977800 int this_instr ;
77987801
7802+ if (misplaced_cmdmod (cctx ))
7803+ return NULL ;
7804+
77997805 // end block scope from :try or :catch
78007806 if (scope != NULL && scope -> se_type == BLOCK_SCOPE )
78017807 compile_endblock (cctx );
@@ -7854,6 +7860,9 @@ compile_endtry(char_u *arg, cctx_T *cctx)
78547860 garray_T * instr = & cctx -> ctx_instr ;
78557861 isn_T * try_isn ;
78567862
7863+ if (misplaced_cmdmod (cctx ))
7864+ return NULL ;
7865+
78577866 // end block scope from :catch or :finally
78587867 if (scope != NULL && scope -> se_type == BLOCK_SCOPE )
78597868 compile_endblock (cctx );
0 commit comments