To: vim_dev@googlegroups.com Subject: Patch 8.2.2186 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ 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 set opfunc=Opfuncg@ + def g:Opfunc(_: any): string + setline(1, 'ASDF') + return '' + enddef + new + setline(1, 'asdf') + feedkeys("\$", 'x') + assert_equal('ASDF', getline(1)) + + bwipe! + nunmap + 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 -- Bram@Moolenaar.net -- 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 ///