Skip to content

Commit 327d3ee

Browse files
committed
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().
1 parent eaf3f36 commit 327d3ee

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/testdir/test_vim9_assign.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,5 +2002,20 @@ def Test_inc_dec()
20022002
CheckDefAndScriptFailure(lines, "E1202: No white space allowed after '++': ++ nr")
20032003
enddef
20042004

2005+
def Test_abort_after_error()
2006+
# should abort after strpart() fails, not give another type error
2007+
var lines =<< trim END
2008+
vim9script
2009+
var x: string
2010+
x = strpart(1, 2)
2011+
END
2012+
writefile(lines, 'Xtestscript')
2013+
var expected = 'E1174: String required for argument 1'
2014+
assert_fails('so Xtestscript', [expected, expected], 3)
2015+
2016+
delete('Xtestscript')
2017+
enddef
2018+
2019+
20052020

20062021
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/userfunc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,8 @@ get_func_tv(
16741674

16751675
if (ret == OK)
16761676
{
1677-
int i = 0;
1677+
int i = 0;
1678+
int did_emsg_before = did_emsg;
16781679

16791680
if (get_vim_var_nr(VV_TESTING))
16801681
{
@@ -1689,6 +1690,10 @@ get_func_tv(
16891690
}
16901691

16911692
ret = call_func(name, len, rettv, argcount, argvars, funcexe);
1693+
if (in_vim9script() && did_emsg > did_emsg_before)
1694+
// An error in a builtin function does not return FAIL, but we do
1695+
// want to abort further processing if an error was given.
1696+
ret = FAIL;
16921697

16931698
funcargs.ga_len -= i;
16941699
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3237,
758760
/**/
759761
3236,
760762
/**/

0 commit comments

Comments
 (0)