# HG changeset patch # User Bram Moolenaar # Date 1608636604 -3600 # Node ID 5b4db8035d1dc73237ed18f5ff6daf9de830e4b2 # Parent a6d48e6961aa2d754c489c09a5a4a0a9f70f030c patch 8.2.2186: Vim9: error when using 'opfunc' Commit: https://github.com/vim/vim/commit/5b3d1bb0f5180266c4de4d815b3ea856a2fb3519 Author: Bram Moolenaar Date: Tue Dec 22 12:20:08 2020 +0100 patch 8.2.2186: Vim9: error when using 'opfunc' Problem: Vim9: error when using 'opfunc'. Solution: Do not expect a return value from 'opfunc'. (closes https://github.com/vim/vim/issues/7510) diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -655,10 +655,27 @@ call_func_retnr( } /* + * 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 * diff --git a/src/ops.c b/src/ops.c --- 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) diff --git a/src/proto/eval.pro b/src/proto/eval.pro --- a/src/proto/eval.pro +++ b/src/proto/eval.pro @@ -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); diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -1976,5 +1976,20 @@ def Test_dict_member_with_silent() 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 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2186, +/**/ 2185, /**/ 2184,