changeset 20287:ce1b73835822 v8.2.0699

patch 8.2.0699: Vim9: not all errors tested Commit: https://github.com/vim/vim/commit/015f4267f4a28627c1872042078a95be7e06c4dc Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 5 21:25:22 2020 +0200 patch 8.2.0699: Vim9: not all errors tested Problem: Vim9: not all errors tested. Solution: Add test for deleted function. Bail out on first error.
author Bram Moolenaar <Bram@vim.org>
date Tue, 05 May 2020 21:30:04 +0200
parents a7b6adc814f1
children 40f2361f79e1
files src/testdir/test_vim9_expr.vim src/testdir/test_vim9_func.vim src/testdir/vim9.vim src/version.c src/vim9execute.c
diffstat 5 files changed, 50 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -759,11 +759,11 @@ def Test_expr7_list()
   assert_equal(g:list_mixed, [1, 'b', false])
   assert_equal('b', g:list_mixed[1])
 
-  call CheckDefExecFailure("let x = g:anint[3]", 'E714:')
+  call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
   call CheckDefFailure(["let x = g:list_mixed[xxx]"], 'E1001:')
-  call CheckDefExecFailure("let x = g:list_mixed['xx']", 'E39:')
+  call CheckDefExecFailure(["let x = g:list_mixed['xx']"], 'E39:')
   call CheckDefFailure(["let x = g:list_mixed[0"], 'E111:')
-  call CheckDefExecFailure("let x = g:list_empty[3]", 'E684:')
+  call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
 enddef
 
 def Test_expr7_lambda()
@@ -792,8 +792,8 @@ def Test_expr7_dict()
   call CheckDefFailure(["let x = #"], 'E1015:')
   call CheckDefFailure(["let x += 1"], 'E1020:')
   call CheckDefFailure(["let x = x + 1"], 'E1001:')
-  call CheckDefExecFailure("let x = g:anint.member", 'E715:')
-  call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
+  call CheckDefExecFailure(["let x = g:anint.member"], 'E715:')
+  call CheckDefExecFailure(["let x = g:dict_empty.member"], 'E716:')
 enddef
 
 def Test_expr_member()
@@ -899,8 +899,8 @@ func Test_expr7_fails()
   call CheckDefFailure(["let x = -'xx'"], "E1030:")
   call CheckDefFailure(["let x = +'xx'"], "E1030:")
   call CheckDefFailure(["let x = -0z12"], "E974:")
-  call CheckDefExecFailure("let x = -[8]", "E39:")
-  call CheckDefExecFailure("let x = -{'a': 1}", "E39:")
+  call CheckDefExecFailure(["let x = -[8]"], "E39:")
+  call CheckDefExecFailure(["let x = -{'a': 1}"], "E39:")
 
   call CheckDefFailure(["let x = @"], "E1002:")
   call CheckDefFailure(["let x = @<"], "E354:")
@@ -914,23 +914,23 @@ func Test_expr7_fails()
   call CheckDefFailure(["let x = &notexist"], 'E113:')
   call CheckDefFailure(["&grepprg = [343]"], 'E1013:')
 
-  call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
-  call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
+  call CheckDefExecFailure(["echo s:doesnt_exist"], 'E121:')
+  call CheckDefExecFailure(["echo g:doesnt_exist"], 'E121:')
 
   call CheckDefFailure(["echo a:somevar"], 'E1075:')
   call CheckDefFailure(["echo l:somevar"], 'E1075:')
   call CheckDefFailure(["echo x:somevar"], 'E1075:')
 
-  call CheckDefExecFailure("let x = +g:astring", 'E1030:')
-  call CheckDefExecFailure("let x = +g:ablob", 'E974:')
-  call CheckDefExecFailure("let x = +g:alist", 'E745:')
-  call CheckDefExecFailure("let x = +g:adict", 'E728:')
+  call CheckDefExecFailure(["let x = +g:astring"], 'E1030:')
+  call CheckDefExecFailure(["let x = +g:ablob"], 'E974:')
+  call CheckDefExecFailure(["let x = +g:alist"], 'E745:')
+  call CheckDefExecFailure(["let x = +g:adict"], 'E728:')
 
   call CheckDefFailure(["let x = ''", "let y = x.memb"], 'E715:')
 
-  call CheckDefExecFailure("[1, 2->len()", 'E492:')
-  call CheckDefExecFailure("#{a: 1->len()", 'E488:')
-  call CheckDefExecFailure("{'a': 1->len()", 'E492:')
+  call CheckDefExecFailure(["[1, 2->len()"], 'E492:')
+  call CheckDefExecFailure(["#{a: 1->len()"], 'E488:')
+  call CheckDefExecFailure(["{'a': 1->len()"], 'E492:')
 endfunc
 
 let g:Funcrefs = [function('add')]
@@ -986,7 +986,7 @@ func Test_expr_fails()
   call CheckDefFailure(["let x = '1'is2"], 'E488:')
   call CheckDefFailure(["let x = '1'isnot2"], 'E488:')
 
-  call CheckDefExecFailure("CallMe ('yes')", 'E492:')
+  call CheckDefExecFailure(["CallMe ('yes')"], 'E492:')
   call CheckDefFailure(["CallMe2('yes','no')"], 'E1069:')
   call CheckDefFailure(["CallMe2('yes' , 'no')"], 'E1068:')
 
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -642,6 +642,23 @@ func Test_E1056_1059()
   call assert_equal(1, caught_1059)
 endfunc
 
+func DelMe()
+  echo 'DelMe'
+endfunc
+
+def Test_deleted_function()
+  CheckDefExecFailure([
+      'let RefMe: func = function("g:DelMe")',
+      'delfunc g:DelMe',
+      'echo RefMe()'], 'E117:')
+enddef
+
+def Test_unknown_function()
+  CheckDefExecFailure([
+      'let Ref: func = function("NotExist")',
+      'delfunc g:NotExist'], 'E700:')
+enddef
+
 def RefFunc(Ref: func(string): string): string
   return Ref('more')
 enddef
--- a/src/testdir/vim9.vim
+++ b/src/testdir/vim9.vim
@@ -7,6 +7,14 @@ func CheckDefFailure(lines, error)
   call delete('Xdef')
 endfunc
 
+" Check that "lines" inside ":def" results in an "error" message when executed.
+func CheckDefExecFailure(lines, error)
+  call writefile(['def Func()'] + a:lines + ['enddef'], 'Xdef')
+  so Xdef
+  call assert_fails('call Func()', a:error, a:lines)
+  call delete('Xdef')
+endfunc
+
 def CheckScriptFailure(lines: list<string>, error: string)
   writefile(lines, 'Xdef')
   assert_fails('so Xdef', error, lines)
@@ -18,11 +26,3 @@ def CheckScriptSuccess(lines: list<strin
   so Xdef
   delete('Xdef')
 enddef
-
-" Check that "line" inside ":def" results in an "error" message when executed.
-func CheckDefExecFailure(line, error)
-  call writefile(['def! Func()', a:line, 'enddef'], 'Xdef')
-  so Xdef
-  call assert_fails('call Func()', a:error, a:line)
-  call delete('Xdef')
-endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    699,
+/**/
     698,
 /**/
     697,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -432,6 +432,7 @@ call_bfunc(int func_idx, int argcount, e
 {
     typval_T	argvars[MAX_FUNC_ARGS];
     int		idx;
+    int		called_emsg_before = called_emsg;
 
     if (call_prepare(argcount, argvars, ectx) == FAIL)
 	return FAIL;
@@ -442,6 +443,9 @@ call_bfunc(int func_idx, int argcount, e
     // Clear the arguments.
     for (idx = 0; idx < argcount; ++idx)
 	clear_tv(&argvars[idx]);
+
+    if (called_emsg != called_emsg_before)
+	return FAIL;
     return OK;
 }
 
@@ -549,7 +553,8 @@ call_partial(typval_T *tv, int argcount,
     if (name == NULL || call_by_name(name, argcount, ectx, NULL) == FAIL)
     {
 	if (called_emsg == called_emsg_before)
-	    semsg(_(e_unknownfunc), name);
+	    semsg(_(e_unknownfunc),
+				  name == NULL ? (char_u *)"[unknown]" : name);
 	return FAIL;
     }
     return OK;