Patch 8.2.2186
Problem:    Vim9: error when using 'opfunc'.
Solution:   Do not expect a return value from 'opfunc'. (closes #7510)
Files:      src/eval.c, src/proto/eval.pro, src/ops.c,
            src/testdir/test_vim9_func.vim


*** ../vim-8.2.2185/src/eval.c  2020-12-19 22:10:09.857835454 +0100
--- src/eval.c  2020-12-22 12:05:47.699832358 +0100
***************
*** 655,664 ****
  }
  
  /*
   * Call Vim script function "func" and return the result as a string.
   * 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(
--- 655,681 ----
  }
  
  /*
+  * 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.
   */
      void *
  call_func_retstr(
***************
*** 679,686 ****
  
  /*
   * 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.
   * Returns NULL when there is something wrong.
   */
      void *
--- 696,702 ----
  
  /*
   * Call Vim script function "func" and return the result as a List.
!  * Uses "argv" and "argc" as call_func_retnr().
   * Returns NULL when there is something wrong.
   */
      void *
*** ../vim-8.2.2185/src/proto/eval.pro  2020-10-28 13:53:46.549128959 +0100
--- src/proto/eval.pro  2020-12-22 12:05:52.579814200 +0100
***************
*** 18,23 ****
--- 18,24 ----
  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);
*** ../vim-8.2.2185/src/ops.c   2020-12-20 13:07:44.817149460 +0100
--- src/ops.c   2020-12-22 12:05:11.883965654 +0100
***************
*** 3299,3305 ****
        // function.
        virtual_op = MAYBE;
  
!       (void)call_func_retnr(p_opfunc, 1, argv);
  
        virtual_op = save_virtual_op;
        if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
--- 3299,3305 ----
        // function.
        virtual_op = MAYBE;
  
!       (void)call_func_noret(p_opfunc, 1, argv);
  
        virtual_op = save_virtual_op;
        if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
*** ../vim-8.2.2185/src/testdir/test_vim9_func.vim      2020-12-20 
21:10:13.902437880 +0100
--- src/testdir/test_vim9_func.vim      2020-12-22 12:08:13.867288651 +0100
***************
*** 1976,1980 ****
--- 1976,1995 ----
    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
*** ../vim-8.2.2185/src/version.c       2020-12-22 12:19:28.321343160 +0100
--- src/version.c       2020-12-22 12:13:49.054042796 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2186,
  /**/

-- 
The average life of an organization chart is six months.  You can safely
ignore any order from your boss that would take six months to complete.
                                (Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012221121.0BMBL3aX2528967%40masaka.moolenaar.net.

Raspunde prin e-mail lui