Mercurial > vim
changeset 25400:5c7192180b89 v8.2.3237
patch 8.2.3237: when a builtin function gives an error processing continues
Commit: https://github.com/vim/vim/commit/327d3ee4557027b51aad86e68743a85ed3a6f52b
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jul 28 19:34:14 2021 +0200
patch 8.2.3237: when a builtin function gives an error processing continues
Problem: When a builtin function gives an error processing continues.
Solution: In Vim9 script return FAIL in get_func_tv().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 28 Jul 2021 19:45:04 +0200 |
parents | 8c4523f3e3b4 |
children | 64c069059e9b |
files | src/testdir/test_vim9_assign.vim src/userfunc.c src/version.c |
diffstat | 3 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -2002,5 +2002,20 @@ def Test_inc_dec() CheckDefAndScriptFailure(lines, "E1202: No white space allowed after '++': ++ nr") enddef +def Test_abort_after_error() + # should abort after strpart() fails, not give another type error + var lines =<< trim END + vim9script + var x: string + x = strpart(1, 2) + END + writefile(lines, 'Xtestscript') + var expected = 'E1174: String required for argument 1' + assert_fails('so Xtestscript', [expected, expected], 3) + + delete('Xtestscript') +enddef + + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -1674,7 +1674,8 @@ get_func_tv( if (ret == OK) { - int i = 0; + int i = 0; + int did_emsg_before = did_emsg; if (get_vim_var_nr(VV_TESTING)) { @@ -1689,6 +1690,10 @@ get_func_tv( } ret = call_func(name, len, rettv, argcount, argvars, funcexe); + if (in_vim9script() && did_emsg > did_emsg_before) + // An error in a builtin function does not return FAIL, but we do + // want to abort further processing if an error was given. + ret = FAIL; funcargs.ga_len -= i; }