@@ -2387,7 +2387,7 @@ misplaced_cmdmod(cctx_T *cctx)
23872387
23882388/*
23892389 * Get the index of the current instruction.
2390- * This compenstates for a preceding ISN_CMDMOD and ISN_PROF_START.
2390+ * This compensates for a preceding ISN_CMDMOD and ISN_PROF_START.
23912391 */
23922392 static int
23932393current_instr_idx (cctx_T * cctx )
@@ -7732,7 +7732,9 @@ compile_elseif(char_u *arg, cctx_T *cctx)
77327732
77337733 if (cctx -> ctx_skip == SKIP_UNKNOWN )
77347734 {
7735- int moved_cmdmod = FALSE;
7735+ int moved_cmdmod = FALSE;
7736+ int saved_debug = FALSE;
7737+ isn_T debug_isn ;
77367738
77377739 // Move any CMDMOD instruction to after the jump
77387740 if (((isn_T * )instr -> ga_data )[instr -> ga_len - 1 ].isn_type == ISN_CMDMOD )
@@ -7745,14 +7747,35 @@ compile_elseif(char_u *arg, cctx_T *cctx)
77457747 moved_cmdmod = TRUE;
77467748 }
77477749
7750+ // Remove the already generated ISN_DEBUG, it is written below the
7751+ // ISN_FOR instruction.
7752+ if (cctx -> ctx_compile_type == CT_DEBUG && instr -> ga_len > 0
7753+ && ((isn_T * )instr -> ga_data )[instr -> ga_len - 1 ]
7754+ .isn_type == ISN_DEBUG )
7755+ {
7756+ -- instr -> ga_len ;
7757+ debug_isn = ((isn_T * )instr -> ga_data )[instr -> ga_len ];
7758+ saved_debug = TRUE;
7759+ }
7760+
77487761 if (compile_jump_to_end (& scope -> se_u .se_if .is_end_label ,
77497762 JUMP_ALWAYS , cctx ) == FAIL )
77507763 return NULL ;
77517764 // previous "if" or "elseif" jumps here
77527765 isn = ((isn_T * )instr -> ga_data ) + scope -> se_u .se_if .is_if_label ;
77537766 isn -> isn_arg .jump .jump_where = instr -> ga_len ;
7767+
77547768 if (moved_cmdmod )
77557769 ++ instr -> ga_len ;
7770+
7771+ if (saved_debug )
7772+ {
7773+ // move the debug instruction here
7774+ if (GA_GROW_FAILS (instr , 1 ))
7775+ return NULL ;
7776+ ((isn_T * )instr -> ga_data )[instr -> ga_len ] = debug_isn ;
7777+ ++ instr -> ga_len ;
7778+ }
77567779 }
77577780
77587781 // compile "expr"; if we know it evaluates to FALSE skip the block
0 commit comments