changeset 24210:083f07f99e20 v8.2.2646

patch 8.2.2646: Vim9: error for not using string doesn't mentionargument Commit: https://github.com/vim/vim/commit/f28f2ac425600b88da0bdcc12a82cd620f575681 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 22 22:21:26 2021 +0100 patch 8.2.2646: Vim9: error for not using string doesn't mentionargument Problem: Vim9: error for not using string doesn't mention argument. Solution: Add argument number.
author Bram Moolenaar <Bram@vim.org>
date Mon, 22 Mar 2021 22:30:03 +0100
parents 3422237ca50e
children f02661b525db
files src/errors.h src/filepath.c src/mbyte.c src/proto/typval.pro src/testdir/test_vim9_builtin.vim src/typval.c src/version.c
diffstat 7 files changed, 76 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/errors.h
+++ b/src/errors.h
@@ -383,3 +383,7 @@ EXTERN char e_cannot_use_default_values_
 	INIT(= N_("E1172: Cannot use default values in a lambda"));
 EXTERN char e_text_found_after_enddef_str[]
 	INIT(= N_("E1173: Text found after enddef: %s"));
+EXTERN char e_string_required_for_argument_nr[]
+	INIT(= N_("E1174: String required for argument %d"));
+EXTERN char e_non_empty_string_required_for_argument_nr[]
+	INIT(= N_("E1142: Non-empty string required for argument %d"));
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -861,7 +861,7 @@ f_delete(typval_T *argvars, typval_T *re
     void
 f_executable(typval_T *argvars, typval_T *rettv)
 {
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
 
     // Check in $PATH and also check directly if there is a directory name.
@@ -876,7 +876,7 @@ f_exepath(typval_T *argvars, typval_T *r
 {
     char_u *p = NULL;
 
-    if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_nonempty_string(&argvars[0], 1) == FAIL)
 	return;
     (void)mch_can_exe(tv_get_string(&argvars[0]), &p, TRUE);
     rettv->v_type = VAR_STRING;
@@ -893,7 +893,7 @@ f_filereadable(typval_T *argvars, typval
     char_u	*p;
     int		n;
 
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
 #ifndef O_NONBLOCK
 # define O_NONBLOCK 0
@@ -918,7 +918,7 @@ f_filereadable(typval_T *argvars, typval
     void
 f_filewritable(typval_T *argvars, typval_T *rettv)
 {
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
     rettv->vval.v_number = filewritable(tv_get_string(&argvars[0]));
 }
@@ -942,7 +942,7 @@ findfilendir(
 
     rettv->vval.v_string = NULL;
     rettv->v_type = VAR_STRING;
-    if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_nonempty_string(&argvars[0], 1) == FAIL)
 	return;
 
 #ifdef FEAT_SEARCHPATH
@@ -1023,8 +1023,8 @@ f_fnamemodify(typval_T *argvars, typval_
     char_u	*fbuf = NULL;
     char_u	buf[NUMBUFLEN];
 
-    if (in_vim9script() && (check_for_string(&argvars[0]) == FAIL
-	    || check_for_string(&argvars[1]) == FAIL))
+    if (in_vim9script() && (check_for_string(&argvars[0], 1) == FAIL
+	    || check_for_string(&argvars[1], 2) == FAIL))
 	return;
     fname = tv_get_string_chk(&argvars[0]);
     mods = tv_get_string_buf_chk(&argvars[1], buf);
@@ -1135,7 +1135,7 @@ f_getfperm(typval_T *argvars, typval_T *
     char_u	*perm = NULL;
     char_u	permbuf[] = "---------";
 
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
     fname = tv_get_string(&argvars[0]);
 
@@ -1154,7 +1154,7 @@ f_getfsize(typval_T *argvars, typval_T *
     char_u	*fname;
     stat_T	st;
 
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
 
     fname = tv_get_string(&argvars[0]);
@@ -1184,7 +1184,7 @@ f_getftime(typval_T *argvars, typval_T *
     char_u	*fname;
     stat_T	st;
 
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
     fname = tv_get_string(&argvars[0]);
     if (mch_stat((char *)fname, &st) >= 0)
@@ -1230,7 +1230,7 @@ f_getftype(typval_T *argvars, typval_T *
     stat_T	st;
     char_u	*type = NULL;
 
-    if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
+    if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
 	return;
     fname = tv_get_string(&argvars[0]);
 
@@ -2410,6 +2410,11 @@ f_browse(typval_T *argvars UNUSED, typva
     char_u	buf2[NUMBUFLEN];
     int		error = FALSE;
 
+    if (in_vim9script()
+	    && (check_for_string(&argvars[1], 2) == FAIL
+		|| check_for_string(&argvars[2], 3) == FAIL
+		|| check_for_string(&argvars[3], 4) == FAIL))
+	return;
     save = (int)tv_get_number_chk(&argvars[0], &error);
     title = tv_get_string_chk(&argvars[1]);
     initdir = tv_get_string_buf_chk(&argvars[2], buf);
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -5551,7 +5551,7 @@ f_setcellwidths(typval_T *argvars, typva
     void
 f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
 {
-    if (check_for_string(&argvars[0]) == FAIL)
+    if (check_for_string(&argvars[0], 1) == FAIL)
 	return;
     rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
 }
--- a/src/proto/typval.pro
+++ b/src/proto/typval.pro
@@ -9,8 +9,8 @@ varnumber_T tv_get_number_chk(typval_T *
 varnumber_T tv_get_bool(typval_T *varp);
 varnumber_T tv_get_bool_chk(typval_T *varp, int *denote);
 float_T tv_get_float(typval_T *varp);
-int check_for_string(typval_T *tv);
-int check_for_nonempty_string(typval_T *tv);
+int check_for_string(typval_T *tv, int arg);
+int check_for_nonempty_string(typval_T *tv, int arg);
 char_u *tv_get_string(typval_T *varp);
 char_u *tv_get_string_strict(typval_T *varp);
 char_u *tv_get_string_buf(typval_T *varp, char_u *buf);
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -125,6 +125,23 @@ def Test_append()
   assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6))
 enddef
 
+def Test_browse()
+  CheckFeature browse
+
+  var lines =<< trim END
+      call browse(1, 2, 3, 4)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2')
+  lines =<< trim END
+      call browse(1, 'title', 3, 4)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
+  lines =<< trim END
+      call browse(1, 'title', 'dir', 4)
+  END
+  CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
+enddef
+
 def Test_buflisted()
   var res: bool = buflisted('asdf')
   assert_equal(false, res)
@@ -223,13 +240,13 @@ def Test_executable()
   assert_false(executable(""))
   assert_false(executable(test_null_string()))
 
-  CheckDefExecFailure(['echo executable(123)'], 'E928:')
-  CheckDefExecFailure(['echo executable(true)'], 'E928:')
+  CheckDefExecFailure(['echo executable(123)'], 'E1174:')
+  CheckDefExecFailure(['echo executable(true)'], 'E1174:')
 enddef
 
 def Test_exepath()
-  CheckDefExecFailure(['echo exepath(true)'], 'E928:')
-  CheckDefExecFailure(['echo exepath(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo exepath(true)'], 'E1174:')
+  CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:')
   CheckDefExecFailure(['echo exepath("")'], 'E1142:')
 enddef
 
@@ -374,27 +391,27 @@ def Test_filereadable()
   assert_false(filereadable(""))
   assert_false(filereadable(test_null_string()))
 
-  CheckDefExecFailure(['echo filereadable(123)'], 'E928:')
-  CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
+  CheckDefExecFailure(['echo filereadable(123)'], 'E1174:')
+  CheckDefExecFailure(['echo filereadable(true)'], 'E1174:')
 enddef
 
 def Test_filewritable()
   assert_false(filewritable(""))
   assert_false(filewritable(test_null_string()))
 
-  CheckDefExecFailure(['echo filewritable(123)'], 'E928:')
-  CheckDefExecFailure(['echo filewritable(true)'], 'E928:')
+  CheckDefExecFailure(['echo filewritable(123)'], 'E1174:')
+  CheckDefExecFailure(['echo filewritable(true)'], 'E1174:')
 enddef
 
 def Test_finddir()
-  CheckDefExecFailure(['echo finddir(true)'], 'E928:')
-  CheckDefExecFailure(['echo finddir(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
+  CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
   CheckDefExecFailure(['echo finddir("")'], 'E1142:')
 enddef
 
 def Test_findfile()
-  CheckDefExecFailure(['echo findfile(true)'], 'E928:')
-  CheckDefExecFailure(['echo findfile(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
+  CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
   CheckDefExecFailure(['echo findfile("")'], 'E1142:')
 enddef
 
@@ -421,9 +438,9 @@ def Test_fnamemodify()
   CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
   CheckDefSuccess(['echo fnamemodify("file", "")'])
 
-  CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E928:')
-  CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E928:')
-  CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E928:')
+  CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1174: String required for argument 1')
+  CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1174: String required for argument 1')
+  CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1174: String required for argument 2')
 enddef
 
 def Wrong_dict_key_type(items: list<number>): list<number>
@@ -524,32 +541,32 @@ def Test_getfperm()
   assert_equal('', getfperm(""))
   assert_equal('', getfperm(test_null_string()))
 
-  CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
-  CheckDefExecFailure(['echo getfperm(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo getfperm(true)'], 'E1174:')
+  CheckDefExecFailure(['echo getfperm(v:null)'], 'E1174:')
 enddef
 
 def Test_getfsize()
   assert_equal(-1, getfsize(""))
   assert_equal(-1, getfsize(test_null_string()))
 
-  CheckDefExecFailure(['echo getfsize(true)'], 'E928:')
-  CheckDefExecFailure(['echo getfsize(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo getfsize(true)'], 'E1174:')
+  CheckDefExecFailure(['echo getfsize(v:null)'], 'E1174:')
 enddef
 
 def Test_getftime()
   assert_equal(-1, getftime(""))
   assert_equal(-1, getftime(test_null_string()))
 
-  CheckDefExecFailure(['echo getftime(true)'], 'E928:')
-  CheckDefExecFailure(['echo getftime(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo getftime(true)'], 'E1174:')
+  CheckDefExecFailure(['echo getftime(v:null)'], 'E1174:')
 enddef
 
 def Test_getftype()
   assert_equal('', getftype(""))
   assert_equal('', getftype(test_null_string()))
 
-  CheckDefExecFailure(['echo getftype(true)'], 'E928:')
-  CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
+  CheckDefExecFailure(['echo getftype(true)'], 'E1174:')
+  CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:')
 enddef
 
 def Test_getqflist_return_type()
--- a/src/typval.c
+++ b/src/typval.c
@@ -344,11 +344,14 @@ tv_get_float(typval_T *varp)
  * Give an error and return FAIL unless "tv" is a string.
  */
     int
-check_for_string(typval_T *tv)
+check_for_string(typval_T *tv, int arg)
 {
     if (tv->v_type != VAR_STRING)
     {
-	emsg(_(e_stringreq));
+	if (arg > 0)
+	    semsg(_(e_string_required_for_argument_nr), arg);
+	else
+	    emsg(_(e_stringreq));
 	return FAIL;
     }
     return OK;
@@ -358,13 +361,16 @@ check_for_string(typval_T *tv)
  * Give an error and return FAIL unless "tv" is a non-empty string.
  */
     int
-check_for_nonempty_string(typval_T *tv)
+check_for_nonempty_string(typval_T *tv, int arg)
 {
-    if (check_for_string(tv) == FAIL)
+    if (check_for_string(tv, arg) == FAIL)
 	return FAIL;
     if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL)
     {
-	emsg(_(e_non_empty_string_required));
+	if (arg > 0)
+	    semsg(_(e_non_empty_string_required_for_argument_nr), arg);
+	else
+	    emsg(_(e_non_empty_string_required));
 	return FAIL;
     }
     return OK;
--- 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 */
 /**/
+    2646,
+/**/
     2645,
 /**/
     2644,