Patch 8.2.2646
Problem: Vim9: error for not using string doesn't mention argument.
Solution: Add argument number.
Files: src/filepath.c, src/typval.c, src/proto/
typval.pro, src/errors.h,
src/mbyte.c, src/testdir/test_vim9_builtin.vim
*** ../vim-8.2.2645/src/filepath.c 2021-02-07 14:01:30.232933727 +0100
--- src/filepath.c 2021-03-22 22:08:00.680151901 +0100
***************
*** 861,867 ****
void
f_executable(typval_T *argvars, typval_T *rettv)
{
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
// Check in $PATH and also check directly if there is a directory name.
--- 861,867 ----
void
f_executable(typval_T *argvars, typval_T *rettv)
{
! 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,882 ****
{
char_u *p = NULL;
! if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
return;
(void)mch_can_exe(tv_get_string(&argvars[0]), &p, TRUE);
rettv->v_type = VAR_STRING;
--- 876,882 ----
{
char_u *p = NULL;
! 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,899 ****
char_u *p;
int n;
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
#ifndef O_NONBLOCK
# define O_NONBLOCK 0
--- 893,899 ----
char_u *p;
int n;
! if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
return;
#ifndef O_NONBLOCK
# define O_NONBLOCK 0
***************
*** 918,924 ****
void
f_filewritable(typval_T *argvars, typval_T *rettv)
{
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
rettv->vval.v_number = filewritable(tv_get_string(&argvars[0]));
}
--- 918,924 ----
void
f_filewritable(typval_T *argvars, typval_T *rettv)
{
! if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
return;
rettv->vval.v_number = filewritable(tv_get_string(&argvars[0]));
}
***************
*** 942,948 ****
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
! if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
return;
#ifdef FEAT_SEARCHPATH
--- 942,948 ----
rettv->vval.v_string = NULL;
rettv->v_type = VAR_STRING;
! if (in_vim9script() && check_for_nonempty_string(&argvars[0], 1) == FAIL)
return;
#ifdef FEAT_SEARCHPATH
***************
*** 1023,1030 ****
char_u *fbuf = NULL;
char_u buf[NUMBUFLEN];
! if (in_vim9script() && (check_for_string(&argvars[0]) == FAIL
! || check_for_string(&argvars[1]) == FAIL))
return;
fname = tv_get_string_chk(&argvars[0]);
mods = tv_get_string_buf_chk(&argvars[1], buf);
--- 1023,1030 ----
char_u *fbuf = NULL;
char_u buf[NUMBUFLEN];
! 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,1141 ****
char_u *perm = NULL;
char_u permbuf[] = "---------";
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
--- 1135,1141 ----
char_u *perm = NULL;
char_u permbuf[] = "---------";
! if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
***************
*** 1154,1160 ****
char_u *fname;
stat_T st;
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
--- 1154,1160 ----
char_u *fname;
stat_T st;
! if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
***************
*** 1184,1190 ****
char_u *fname;
stat_T st;
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
if (mch_stat((char *)fname, &st) >= 0)
--- 1184,1190 ----
char_u *fname;
stat_T st;
! 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,1236 ****
stat_T st;
char_u *type = NULL;
! if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
--- 1230,1236 ----
stat_T st;
char_u *type = NULL;
! if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
return;
fname = tv_get_string(&argvars[0]);
***************
*** 2410,2415 ****
--- 2410,2420 ----
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);
*** ../vim-8.2.2645/src/typval.c 2021-02-10 22:23:36.398613504 +0100
--- src/typval.c 2021-03-22 22:01:53.037614128 +0100
***************
*** 344,354 ****
* Give an error and return FAIL unless "tv" is a string.
*/
int
! check_for_string(typval_T *tv)
{
if (tv->v_type != VAR_STRING)
{
! emsg(_(e_stringreq));
return FAIL;
}
return OK;
--- 344,357 ----
* Give an error and return FAIL unless "tv" is a string.
*/
int
! check_for_string(typval_T *tv, int arg)
{
if (tv->v_type != VAR_STRING)
{
! if (arg > 0)
! semsg(_(e_string_required_for_argument_nr), arg);
! else
! emsg(_(e_stringreq));
return FAIL;
}
return OK;
***************
*** 358,370 ****
* Give an error and return FAIL unless "tv" is a non-empty string.
*/
int
! check_for_nonempty_string(typval_T *tv)
{
! if (check_for_string(tv) == FAIL)
return FAIL;
if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL)
{
! emsg(_(e_non_empty_string_required));
return FAIL;
}
return OK;
--- 361,376 ----
* Give an error and return FAIL unless "tv" is a non-empty string.
*/
int
! check_for_nonempty_string(typval_T *tv, int arg)
{
! if (check_for_string(tv, arg) == FAIL)
return FAIL;
if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL)
{
! if (arg > 0)
! semsg(_(e_non_empty_string_required_for_argument_nr), arg);
! else
! emsg(_(e_non_empty_string_required));
return FAIL;
}
return OK;
*** ../vim-8.2.2645/src/proto/
typval.pro 2021-01-31 13:08:16.164367438 +0100
--- src/proto/
typval.pro 2021-03-22 22:05:12.524793923 +0100
***************
*** 9,16 ****
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);
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);
--- 9,16 ----
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 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);
*** ../vim-8.2.2645/src/errors.h 2021-03-22 20:48:57.863992154 +0100
--- src/errors.h 2021-03-22 22:02:13.677525615 +0100
***************
*** 383,385 ****
--- 383,389 ----
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"));
*** ../vim-8.2.2645/src/mbyte.c 2021-01-10 22:56:33.486767344 +0100
--- src/mbyte.c 2021-03-22 22:03:42.853153405 +0100
***************
*** 5551,5557 ****
void
f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
{
! if (check_for_string(&argvars[0]) == FAIL)
return;
rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
}
--- 5551,5557 ----
void
f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
{
! if (check_for_string(&argvars[0], 1) == FAIL)
return;
rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
}
*** ../vim-8.2.2645/src/testdir/test_vim9_builtin.vim 2021-03-13 21:24:53.040409187 +0100
--- src/testdir/test_vim9_builtin.vim 2021-03-22 22:19:34.937752668 +0100
***************
*** 125,130 ****
--- 125,147 ----
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,235 ****
assert_false(executable(""))
assert_false(executable(test_null_string()))
! CheckDefExecFailure(['echo executable(123)'], 'E928:')
! CheckDefExecFailure(['echo executable(true)'], 'E928:')
enddef
def Test_exepath()
! CheckDefExecFailure(['echo exepath(true)'], 'E928:')
! CheckDefExecFailure(['echo exepath(v:null)'], 'E928:')
CheckDefExecFailure(['echo exepath("")'], 'E1142:')
enddef
--- 240,252 ----
assert_false(executable(""))
assert_false(executable(test_null_string()))
! CheckDefExecFailure(['echo executable(123)'], 'E1174:')
! CheckDefExecFailure(['echo executable(true)'], 'E1174:')
enddef
def Test_exepath()
! CheckDefExecFailure(['echo exepath(true)'], 'E1174:')
! CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:')
CheckDefExecFailure(['echo exepath("")'], 'E1142:')
enddef
***************
*** 374,400 ****
assert_false(filereadable(""))
assert_false(filereadable(test_null_string()))
! CheckDefExecFailure(['echo filereadable(123)'], 'E928:')
! CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
enddef
def Test_filewritable()
assert_false(filewritable(""))
assert_false(filewritable(test_null_string()))
! CheckDefExecFailure(['echo filewritable(123)'], 'E928:')
! CheckDefExecFailure(['echo filewritable(true)'], 'E928:')
enddef
def Test_finddir()
! CheckDefExecFailure(['echo finddir(true)'], 'E928:')
! CheckDefExecFailure(['echo finddir(v:null)'], 'E928:')
CheckDefExecFailure(['echo finddir("")'], 'E1142:')
enddef
def Test_findfile()
! CheckDefExecFailure(['echo findfile(true)'], 'E928:')
! CheckDefExecFailure(['echo findfile(v:null)'], 'E928:')
CheckDefExecFailure(['echo findfile("")'], 'E1142:')
enddef
--- 391,417 ----
assert_false(filereadable(""))
assert_false(filereadable(test_null_string()))
! 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)'], 'E1174:')
! CheckDefExecFailure(['echo filewritable(true)'], 'E1174:')
enddef
def Test_finddir()
! CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
! CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
CheckDefExecFailure(['echo finddir("")'], 'E1142:')
enddef
def Test_findfile()
! CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
! CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
CheckDefExecFailure(['echo findfile("")'], 'E1142:')
enddef
***************
*** 421,429 ****
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:')
enddef
def Wrong_dict_key_type(items: list<number>): list<number>
--- 438,446 ----
CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
CheckDefSuccess(['echo fnamemodify("file", "")'])
! 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,555 ****
assert_equal('', getfperm(""))
assert_equal('', getfperm(test_null_string()))
! CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
! CheckDefExecFailure(['echo getfperm(v:null)'], 'E928:')
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:')
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:')
enddef
def Test_getftype()
assert_equal('', getftype(""))
assert_equal('', getftype(test_null_string()))
! CheckDefExecFailure(['echo getftype(true)'], 'E928:')
! CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
enddef
def Test_getqflist_return_type()
--- 541,572 ----
assert_equal('', getfperm(""))
assert_equal('', getfperm(test_null_string()))
! 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)'], '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)'], 'E1174:')
! CheckDefExecFailure(['echo getftime(v:null)'], 'E1174:')
enddef
def Test_getftype()
assert_equal('', getftype(""))
assert_equal('', getftype(test_null_string()))
! CheckDefExecFailure(['echo getftype(true)'], 'E1174:')
! CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:')
enddef
def Test_getqflist_return_type()
*** ../vim-8.2.2645/src/version.c 2021-03-22 20:48:57.863992154 +0100
--- src/version.c 2021-03-22 22:19:58.689674570 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2646,
/**/
--
hundred-and-one symptoms of being an internet addict:
20. When looking at a pageful of someone else's links, you notice all of them
are already highlighted in purple.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///