]> granicus.if.org Git - vim/commitdiff
patch 8.2.2186: Vim9: error when using 'opfunc' v8.2.2186
authorBram Moolenaar <Bram@vim.org>
Tue, 22 Dec 2020 11:20:08 +0000 (12:20 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 22 Dec 2020 11:20:08 +0000 (12:20 +0100)
Problem:    Vim9: error when using 'opfunc'.
Solution:   Do not expect a return value from 'opfunc'. (closes #7510)

src/eval.c
src/ops.c
src/proto/eval.pro
src/testdir/test_vim9_func.vim
src/version.c

index f84491e043a6eae1fc3e6afa295ca3a8d0143730..f08ae578f5ba3c49f64f8c3d8c3b05075a40ba64 100644 (file)
@@ -654,11 +654,28 @@ call_func_retnr(
     return retval;
 }
 
+/*
+ * Call Vim script function like call_func_retnr() and drop the result.
+ * Returns FAIL when calling the function fails.
+ */
+    int
+call_func_noret(
+    char_u      *func,
+    int                argc,
+    typval_T   *argv)
+{
+    typval_T   rettv;
+
+    if (call_vim_function(func, argc, argv, &rettv) == FAIL)
+       return FAIL;
+    clear_tv(&rettv);
+    return OK;
+}
+
 /*
  * Call Vim script function "func" and return the result as a string.
+ * Uses "argv" and "argc" as call_func_retnr().
  * Returns NULL when calling the function fails.
- * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should
- * have type VAR_UNKNOWN.
  */
     void *
 call_func_retstr(
@@ -679,8 +696,7 @@ call_func_retstr(
 
 /*
  * Call Vim script function "func" and return the result as a List.
- * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should
- * have type VAR_UNKNOWN.
+ * Uses "argv" and "argc" as call_func_retnr().
  * Returns NULL when there is something wrong.
  */
     void *
index 743bdd43da56cc06ed85ba5ad485fa0fbdf3076c..53bd084ec026414cc76c5fe5a2ef65a29c0a55b8 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -3299,7 +3299,7 @@ op_function(oparg_T *oap UNUSED)
        // function.
        virtual_op = MAYBE;
 
-       (void)call_func_retnr(p_opfunc, 1, argv);
+       (void)call_func_noret(p_opfunc, 1, argv);
 
        virtual_op = save_virtual_op;
        if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
index b1a2c0f143c8f7cd19d0d9732276bdf55f5f66d3..8fa908c5c7e417687fc550ebde23d27b3d80518a 100644 (file)
@@ -18,6 +18,7 @@ varnumber_T eval_to_number(char_u *expr);
 typval_T *eval_expr(char_u *arg, exarg_T *eap);
 int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
 varnumber_T call_func_retnr(char_u *func, int argc, typval_T *argv);
+int call_func_noret(char_u *func, int argc, typval_T *argv);
 void *call_func_retstr(char_u *func, int argc, typval_T *argv);
 void *call_func_retlist(char_u *func, int argc, typval_T *argv);
 int eval_foldexpr(char_u *arg, int *cp);
index 4a0c7a90c0c5ed81a50e80950f90b7d863c3f049..fcfe41f2f47b4ba178f65cc35ba462afa5f34f40 100644 (file)
@@ -1976,5 +1976,20 @@ def Test_dict_member_with_silent()
   CheckScriptSuccess(lines)
 enddef
 
+def Test_opfunc()
+  nnoremap <F3> <cmd>set opfunc=Opfunc<cr>g@
+  def g:Opfunc(_: any): string
+    setline(1, 'ASDF')
+    return ''
+  enddef
+  new
+  setline(1, 'asdf')
+  feedkeys("\<F3>$", 'x')
+  assert_equal('ASDF', getline(1))
+
+  bwipe!
+  nunmap <F3>
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index d18033e4c6e7a7e72eb9c1f6090c03d6a074dc7a..a99765c256ebd70a725de41bc45a55a3b5d98f05 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2186,
 /**/
     2185,
 /**/