]> granicus.if.org Git - vim/commitdiff
patch 8.2.2602: Vim9: continue doesn't work if :while is very first command v8.2.2602
authorBram Moolenaar <Bram@vim.org>
Sun, 14 Mar 2021 11:13:33 +0000 (12:13 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 14 Mar 2021 11:13:33 +0000 (12:13 +0100)
Problem:    Vim9: continue doesn't work if :while is very first command.
            (Yegappan Lakshmanan)
Solution:   Add one to the continue instruction index.

src/testdir/test_vim9_script.vim
src/version.c
src/vim9execute.c

index 78ff44b9366345ca1768e2293d259738690da647..c476acf8963ce414f3f6dbe8c209feaa3661bcd6 100644 (file)
@@ -592,6 +592,31 @@ def Test_try_catch_throw()
   assert_equal(4, ReturnInFinally())
 enddef
 
+" :while at the very start of a function that :continue jumps to
+def TryContinueFunc()
+ while g:Count < 2
+   g:sequence ..= 't'
+    try
+      echoerr 'Test'
+    catch
+      g:Count += 1
+      g:sequence ..= 'c'
+      continue
+    endtry
+    g:sequence ..= 'e'
+    g:Count += 1
+  endwhile
+enddef
+
+def Test_continue_in_try_in_while()
+  g:Count = 0
+  g:sequence = ''
+  TryContinueFunc()
+  assert_equal('tctc', g:sequence)
+  unlet g:Count
+  unlet g:sequence
+enddef
+
 def Test_nocatch_return_in_try()
   # return in try block returns normally
   def ReturnInTry(): string
index 0b9337240ce49c8594dd06f223e200deb9379562..5f950831b7f6e18a6b98f3004d0798c3cbc38edb 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2602,
 /**/
     2601,
 /**/
index f8470f5c7723742b7916d3721777ec3aa19b84f5..b2c28a31bcce44b2832142985b56daff82fcc4ce 100644 (file)
@@ -30,7 +30,7 @@ typedef struct {
     int            tcd_finally_idx;    // instruction of the :finally block or zero
     int            tcd_endtry_idx;     // instruction of the :endtry
     int            tcd_caught;         // catch block entered
-    int            tcd_cont;           // :continue encountered, jump here
+    int            tcd_cont;           // :continue encountered, jump here (minus one)
     int            tcd_return;         // when TRUE return from end of :finally
 } trycmd_T;
 
@@ -2757,7 +2757,9 @@ call_def_function(
                    {
                        trycmd = ((trycmd_T *)trystack->ga_data)
                                                        + trystack->ga_len - i;
-                       trycmd->tcd_cont = iidx;
+                       // Add one to tcd_cont to be able to jump to
+                       // instruction with index zero.
+                       trycmd->tcd_cont = iidx + 1;
                        iidx = trycmd->tcd_finally_idx == 0
                            ? trycmd->tcd_endtry_idx : trycmd->tcd_finally_idx;
                    }
@@ -2811,7 +2813,7 @@ call_def_function(
                        if (trycmd->tcd_cont != 0)
                            // handling :continue: jump to outer try block or
                            // start of the loop
-                           ectx.ec_iidx = trycmd->tcd_cont;
+                           ectx.ec_iidx = trycmd->tcd_cont - 1;
                    }
                }
                break;