summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-03-22 22:21:26 +0100
committerBram Moolenaar <Bram@vim.org>2021-03-22 22:21:26 +0100
commitf28f2ac425600b88da0bdcc12a82cd620f575681 (patch)
treeb8101a4aee337f1b41dbd51f6e8cea5a6c48a2ff
parent49f1e9ec3e7f4e1b3572367d02a83c2b6ebbed97 (diff)
patch 8.2.2646: Vim9: error for not using string doesn't mentionargumentv8.2.2646
Problem: Vim9: error for not using string doesn't mention argument. Solution: Add argument number.
-rw-r--r--src/errors.h4
-rw-r--r--src/filepath.c27
-rw-r--r--src/mbyte.c2
-rw-r--r--src/proto/typval.pro4
-rw-r--r--src/testdir/test_vim9_builtin.vim63
-rw-r--r--src/typval.c16
-rw-r--r--src/version.c2
7 files changed, 76 insertions, 42 deletions
diff --git a/src/errors.h b/src/errors.h
index e610d28ad0..ad3242cac6 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -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"));
diff --git a/src/filepath.c b/src/filepath.c
index 8e54e5bcf8..2f3b90f8e5 100644
--- a/src/filepath.c
+++ b/src/filepath.c
@@ -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);
diff --git a/src/mbyte.c b/src/mbyte.c
index bafab87ace..33b9ace779 100644
--- a/src/mbyte.c
+++ b/src/mbyte.c
@@ -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);
}
diff --git a/src/proto/typval.pro b/src/proto/typval.pro
index ca4fe96723..102821d3cf 100644
--- a/src/proto/typval.pro
+++ b/src/proto/typval.pro
@@ -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);
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 75bbc0c506..b6f387666f 100644
--- 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()
diff --git a/src/typval.c b/src/typval.c
index 1cdab93ef1..6c4da0cf95 100644
--- 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;
diff --git a/src/version.c b/src/version.c
index 9b21d12c0c..b8b5d58a9a 100644
--- 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,