]> granicus.if.org Git - vim/commitdiff
patch 8.2.2096: Vim9: command modifiers not restored after assignment v8.2.2096
authorBram Moolenaar <Bram@vim.org>
Sat, 5 Dec 2020 18:17:16 +0000 (19:17 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 5 Dec 2020 18:17:16 +0000 (19:17 +0100)
Problem:    Vim9: command modifiers not restored after assignment.
Solution:   Jump to nextline instead of using continue.

src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c
src/vim9execute.c

index 18864cfd18f5d621badd9989cbd7797d5a890db0..4e8ee888dae0ef285a0f47f5e1618b1524d8831c 100644 (file)
@@ -1784,6 +1784,22 @@ def Test_reset_did_emsg()
   delfunc! g:Func
 enddef
 
+def Test_continues_with_silent_error()
+  var lines =<< trim END
+      vim9script
+      g:result = 'none'
+      def Func()
+        silent!  g:result += 3
+        g:result = 'yes'
+      enddef
+      # error is silenced, function does not abort
+      Func()
+      assert_equal('yes', g:result)
+      unlet g:result
+  END
+  CheckScriptSuccess(lines)
+enddef
+
 def Test_abort_even_with_silent()
   var lines =<< trim END
       vim9script
@@ -1792,13 +1808,38 @@ def Test_abort_even_with_silent()
         eval {-> ''}() .. '' .. {}['X']
         g:result = 'yes'
       enddef
-      sil! Func()
+      silent! Func()
       assert_equal('none', g:result)
       unlet g:result
   END
   CheckScriptSuccess(lines)
 enddef
 
+def Test_cmdmod_silent_restored()
+  var lines =<< trim END
+      vim9script
+      def Func()
+        g:result = 'none'
+        silent! g:result += 3
+        g:result = 'none'
+        g:result += 3
+      enddef
+      Func()
+  END
+  # can't use CheckScriptFailure, it ignores the :silent!
+  var fname = 'Xdefsilent'
+  writefile(lines, fname)
+  var caught = 'no'
+  try
+    exe 'source ' .. fname
+  catch /E1030:/
+    caught = 'yes'
+    assert_match('Func, line 4', v:throwpoint)
+  endtry
+  assert_equal('yes', caught)
+  delete(fname)
+enddef
+
 def Test_dict_member_with_silent()
   var lines =<< trim END
       vim9script
index cfc1639d4a3e88b8f0a9bcf1889c63d94a7e125a..66ec86a2097de3879362a98fea513662f12ce3c9 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2096,
 /**/
     2095,
 /**/
index 2cd4b52c0abfc4595432b4b0efa872c1411c4c41..ee3d89e517309c6e74ef8d7ab0a94b3aac369052 100644 (file)
@@ -1933,14 +1933,8 @@ generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod)
     static int
 generate_undo_cmdmods(cctx_T *cctx)
 {
-    isn_T      *isn;
-
-    if (cctx->ctx_has_cmdmod)
-    {
-       if ((isn = generate_instr(cctx, ISN_CMDMOD_REV)) == NULL)
-           return FAIL;
-    }
-
+    if (cctx->ctx_has_cmdmod && generate_instr(cctx, ISN_CMDMOD_REV) == NULL)
+       return FAIL;
     return OK;
 }
 
@@ -7578,7 +7572,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
                        line = compile_assignment(ea.cmd, &ea, CMD_SIZE, &cctx);
                        if (line == NULL || line == ea.cmd)
                            goto erret;
-                       continue;
+                       goto nextline;
                    }
                }
            }
@@ -7590,7 +7584,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
                if (line == NULL)
                    goto erret;
                if (line != ea.cmd)
-                   continue;
+                   goto nextline;
            }
        }
 
@@ -7629,7 +7623,7 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
            if (cctx.ctx_skip == SKIP_YES)
            {
                line += STRLEN(line);
-               continue;
+               goto nextline;
            }
 
            // Expression or function call.
index dd36cfa6bcd31d5747e8ff99117d497449ddaac1..980ebb51a855bb520a9c8e3f9bb923a27c6c373f 100644 (file)
@@ -2432,6 +2432,7 @@ call_def_function(
                    else
 #endif
                    {
+                       SOURCING_LNUM = iptr->isn_lnum;
                        n1 = tv_get_number_chk(tv1, &error);
                        if (error)
                            goto on_error;