Skip to content

Commit 2e34c34

Browse files
committed
patch 8.2.2602: Vim9: continue doesn't work if :while is very first command
Problem: Vim9: continue doesn't work if :while is very first command. (Yegappan Lakshmanan) Solution: Add one to the continue instruction index.
1 parent 6bce585 commit 2e34c34

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,31 @@ def Test_try_catch_throw()
592592
assert_equal(4, ReturnInFinally())
593593
enddef
594594

595+
" :while at the very start of a function that :continue jumps to
596+
def TryContinueFunc()
597+
while g:Count < 2
598+
g:sequence ..= 't'
599+
try
600+
echoerr 'Test'
601+
catch
602+
g:Count += 1
603+
g:sequence ..= 'c'
604+
continue
605+
endtry
606+
g:sequence ..= 'e'
607+
g:Count += 1
608+
endwhile
609+
enddef
610+
611+
def Test_continue_in_try_in_while()
612+
g:Count = 0
613+
g:sequence = ''
614+
TryContinueFunc()
615+
assert_equal('tctc', g:sequence)
616+
unlet g:Count
617+
unlet g:sequence
618+
enddef
619+
595620
def Test_nocatch_return_in_try()
596621
# return in try block returns normally
597622
def ReturnInTry(): string

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2602,
753755
/**/
754756
2601,
755757
/**/

src/vim9execute.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typedef struct {
3030
int tcd_finally_idx; // instruction of the :finally block or zero
3131
int tcd_endtry_idx; // instruction of the :endtry
3232
int tcd_caught; // catch block entered
33-
int tcd_cont; // :continue encountered, jump here
33+
int tcd_cont; // :continue encountered, jump here (minus one)
3434
int tcd_return; // when TRUE return from end of :finally
3535
} trycmd_T;
3636

@@ -2757,7 +2757,9 @@ call_def_function(
27572757
{
27582758
trycmd = ((trycmd_T *)trystack->ga_data)
27592759
+ trystack->ga_len - i;
2760-
trycmd->tcd_cont = iidx;
2760+
// Add one to tcd_cont to be able to jump to
2761+
// instruction with index zero.
2762+
trycmd->tcd_cont = iidx + 1;
27612763
iidx = trycmd->tcd_finally_idx == 0
27622764
? trycmd->tcd_endtry_idx : trycmd->tcd_finally_idx;
27632765
}
@@ -2811,7 +2813,7 @@ call_def_function(
28112813
if (trycmd->tcd_cont != 0)
28122814
// handling :continue: jump to outer try block or
28132815
// start of the loop
2814-
ectx.ec_iidx = trycmd->tcd_cont;
2816+
ectx.ec_iidx = trycmd->tcd_cont - 1;
28152817
}
28162818
}
28172819
break;

0 commit comments

Comments
 (0)