]> granicus.if.org Git - vim/commitdiff
patch 8.2.2646: Vim9: error for not using string doesn't mentionargument v8.2.2646
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Mar 2021 21:21:26 +0000 (22:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Mar 2021 21:21:26 +0000 (22:21 +0100)
Problem:    Vim9: error for not using string doesn't mention argument.
Solution:   Add argument number.

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

index e610d28ad0ed22a62ee35042b430eb1129e3490b..ad3242cac689d3af563890f32d4fb2641de7c32a 100644 (file)
@@ -383,3 +383,7 @@ EXTERN char e_cannot_use_default_values_in_lambda[]
        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"));
index 8e54e5bcf87c10303c0dcd31d3542ed47bd0203c..2f3b90f8e5bf4702be8e5eb98f40dbf67b672491 100644 (file)
@@ -861,7 +861,7 @@ f_delete(typval_T *argvars, typval_T *rettv)
     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 *rettv)
 {
     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_T *rettv)
     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_T *rettv)
     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_T *rettv)
     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 *rettv)
     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 *rettv)
     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 *rettv)
     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 *rettv)
     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, typval_T *rettv)
     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);
index bafab87ace1dbd2a7a426892d96ca67211c76695..33b9ace779ce2477ac78defc96237df6e1b797bc 100644 (file)
@@ -5551,7 +5551,7 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
     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);
 }
index ca4fe96723569351dd4b60065f4b0d88f03aa523..102821d3cfbbfefd557e8953e8be3e53dade7f26 100644 (file)
@@ -9,8 +9,8 @@ varnumber_T tv_get_number_chk(typval_T *varp, int *denote);
 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);
index 75bbc0c506bd05a7d83479e4b0a8747c730344bf..b6f387666f7cd17946b36f3325d92dbde84e52ec 100644 (file)
@@ -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()
index 1cdab93ef11d64235570d8ceab0e38756d964b37..6c4da0cf9573d4cf7635557323054d1994a962ac 100644 (file)
@@ -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;
index 9b21d12c0c8156716bc6b645aa67312953fa8e7c..b8b5d58a9a74eacc1e7f7b9731da67a61f29fea1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2646,
 /**/
     2645,
 /**/