Skip to content

Commit f28f2ac

Browse files
committed
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.
1 parent 49f1e9e commit f28f2ac

File tree

7 files changed

+76
-42
lines changed

7 files changed

+76
-42
lines changed

src/errors.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,7 @@ EXTERN char e_cannot_use_default_values_in_lambda[]
383383
INIT(= N_("E1172: Cannot use default values in a lambda"));
384384
EXTERN char e_text_found_after_enddef_str[]
385385
INIT(= N_("E1173: Text found after enddef: %s"));
386+
EXTERN char e_string_required_for_argument_nr[]
387+
INIT(= N_("E1174: String required for argument %d"));
388+
EXTERN char e_non_empty_string_required_for_argument_nr[]
389+
INIT(= N_("E1142: Non-empty string required for argument %d"));

src/filepath.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ f_delete(typval_T *argvars, typval_T *rettv)
861861
void
862862
f_executable(typval_T *argvars, typval_T *rettv)
863863
{
864-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
864+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
865865
return;
866866

867867
// 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)
876876
{
877877
char_u *p = NULL;
878878

879-
if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
879+
if (in_vim9script() && check_for_nonempty_string(&argvars[0], 1) == FAIL)
880880
return;
881881
(void)mch_can_exe(tv_get_string(&argvars[0]), &p, TRUE);
882882
rettv->v_type = VAR_STRING;
@@ -893,7 +893,7 @@ f_filereadable(typval_T *argvars, typval_T *rettv)
893893
char_u *p;
894894
int n;
895895

896-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
896+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
897897
return;
898898
#ifndef O_NONBLOCK
899899
# define O_NONBLOCK 0
@@ -918,7 +918,7 @@ f_filereadable(typval_T *argvars, typval_T *rettv)
918918
void
919919
f_filewritable(typval_T *argvars, typval_T *rettv)
920920
{
921-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
921+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
922922
return;
923923
rettv->vval.v_number = filewritable(tv_get_string(&argvars[0]));
924924
}
@@ -942,7 +942,7 @@ findfilendir(
942942

943943
rettv->vval.v_string = NULL;
944944
rettv->v_type = VAR_STRING;
945-
if (in_vim9script() && check_for_nonempty_string(&argvars[0]) == FAIL)
945+
if (in_vim9script() && check_for_nonempty_string(&argvars[0], 1) == FAIL)
946946
return;
947947

948948
#ifdef FEAT_SEARCHPATH
@@ -1023,8 +1023,8 @@ f_fnamemodify(typval_T *argvars, typval_T *rettv)
10231023
char_u *fbuf = NULL;
10241024
char_u buf[NUMBUFLEN];
10251025

1026-
if (in_vim9script() && (check_for_string(&argvars[0]) == FAIL
1027-
|| check_for_string(&argvars[1]) == FAIL))
1026+
if (in_vim9script() && (check_for_string(&argvars[0], 1) == FAIL
1027+
|| check_for_string(&argvars[1], 2) == FAIL))
10281028
return;
10291029
fname = tv_get_string_chk(&argvars[0]);
10301030
mods = tv_get_string_buf_chk(&argvars[1], buf);
@@ -1135,7 +1135,7 @@ f_getfperm(typval_T *argvars, typval_T *rettv)
11351135
char_u *perm = NULL;
11361136
char_u permbuf[] = "---------";
11371137

1138-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
1138+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
11391139
return;
11401140
fname = tv_get_string(&argvars[0]);
11411141

@@ -1154,7 +1154,7 @@ f_getfsize(typval_T *argvars, typval_T *rettv)
11541154
char_u *fname;
11551155
stat_T st;
11561156

1157-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
1157+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
11581158
return;
11591159

11601160
fname = tv_get_string(&argvars[0]);
@@ -1184,7 +1184,7 @@ f_getftime(typval_T *argvars, typval_T *rettv)
11841184
char_u *fname;
11851185
stat_T st;
11861186

1187-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
1187+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
11881188
return;
11891189
fname = tv_get_string(&argvars[0]);
11901190
if (mch_stat((char *)fname, &st) >= 0)
@@ -1230,7 +1230,7 @@ f_getftype(typval_T *argvars, typval_T *rettv)
12301230
stat_T st;
12311231
char_u *type = NULL;
12321232

1233-
if (in_vim9script() && check_for_string(&argvars[0]) == FAIL)
1233+
if (in_vim9script() && check_for_string(&argvars[0], 1) == FAIL)
12341234
return;
12351235
fname = tv_get_string(&argvars[0]);
12361236

@@ -2410,6 +2410,11 @@ f_browse(typval_T *argvars UNUSED, typval_T *rettv)
24102410
char_u buf2[NUMBUFLEN];
24112411
int error = FALSE;
24122412

2413+
if (in_vim9script()
2414+
&& (check_for_string(&argvars[1], 2) == FAIL
2415+
|| check_for_string(&argvars[2], 3) == FAIL
2416+
|| check_for_string(&argvars[3], 4) == FAIL))
2417+
return;
24132418
save = (int)tv_get_number_chk(&argvars[0], &error);
24142419
title = tv_get_string_chk(&argvars[1]);
24152420
initdir = tv_get_string_buf_chk(&argvars[2], buf);

src/mbyte.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5551,7 +5551,7 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
55515551
void
55525552
f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
55535553
{
5554-
if (check_for_string(&argvars[0]) == FAIL)
5554+
if (check_for_string(&argvars[0], 1) == FAIL)
55555555
return;
55565556
rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
55575557
}

src/proto/typval.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ varnumber_T tv_get_number_chk(typval_T *varp, int *denote);
99
varnumber_T tv_get_bool(typval_T *varp);
1010
varnumber_T tv_get_bool_chk(typval_T *varp, int *denote);
1111
float_T tv_get_float(typval_T *varp);
12-
int check_for_string(typval_T *tv);
13-
int check_for_nonempty_string(typval_T *tv);
12+
int check_for_string(typval_T *tv, int arg);
13+
int check_for_nonempty_string(typval_T *tv, int arg);
1414
char_u *tv_get_string(typval_T *varp);
1515
char_u *tv_get_string_strict(typval_T *varp);
1616
char_u *tv_get_string_buf(typval_T *varp, char_u *buf);

src/testdir/test_vim9_builtin.vim

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ def Test_append()
125125
assert_equal(['0', 'one', '1', 'two', '2'], getline(1, 6))
126126
enddef
127127

128+
def Test_browse()
129+
CheckFeature browse
130+
131+
var lines =<< trim END
132+
call browse(1, 2, 3, 4)
133+
END
134+
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 2')
135+
lines =<< trim END
136+
call browse(1, 'title', 3, 4)
137+
END
138+
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 3')
139+
lines =<< trim END
140+
call browse(1, 'title', 'dir', 4)
141+
END
142+
CheckDefExecAndScriptFailure(lines, 'E1174: String required for argument 4')
143+
enddef
144+
128145
def Test_buflisted()
129146
var res: bool = buflisted('asdf')
130147
assert_equal(false, res)
@@ -223,13 +240,13 @@ def Test_executable()
223240
assert_false(executable(""))
224241
assert_false(executable(test_null_string()))
225242

226-
CheckDefExecFailure(['echo executable(123)'], 'E928:')
227-
CheckDefExecFailure(['echo executable(true)'], 'E928:')
243+
CheckDefExecFailure(['echo executable(123)'], 'E1174:')
244+
CheckDefExecFailure(['echo executable(true)'], 'E1174:')
228245
enddef
229246

230247
def Test_exepath()
231-
CheckDefExecFailure(['echo exepath(true)'], 'E928:')
232-
CheckDefExecFailure(['echo exepath(v:null)'], 'E928:')
248+
CheckDefExecFailure(['echo exepath(true)'], 'E1174:')
249+
CheckDefExecFailure(['echo exepath(v:null)'], 'E1174:')
233250
CheckDefExecFailure(['echo exepath("")'], 'E1142:')
234251
enddef
235252

@@ -374,27 +391,27 @@ def Test_filereadable()
374391
assert_false(filereadable(""))
375392
assert_false(filereadable(test_null_string()))
376393

377-
CheckDefExecFailure(['echo filereadable(123)'], 'E928:')
378-
CheckDefExecFailure(['echo filereadable(true)'], 'E928:')
394+
CheckDefExecFailure(['echo filereadable(123)'], 'E1174:')
395+
CheckDefExecFailure(['echo filereadable(true)'], 'E1174:')
379396
enddef
380397

381398
def Test_filewritable()
382399
assert_false(filewritable(""))
383400
assert_false(filewritable(test_null_string()))
384401

385-
CheckDefExecFailure(['echo filewritable(123)'], 'E928:')
386-
CheckDefExecFailure(['echo filewritable(true)'], 'E928:')
402+
CheckDefExecFailure(['echo filewritable(123)'], 'E1174:')
403+
CheckDefExecFailure(['echo filewritable(true)'], 'E1174:')
387404
enddef
388405

389406
def Test_finddir()
390-
CheckDefExecFailure(['echo finddir(true)'], 'E928:')
391-
CheckDefExecFailure(['echo finddir(v:null)'], 'E928:')
407+
CheckDefExecFailure(['echo finddir(true)'], 'E1174:')
408+
CheckDefExecFailure(['echo finddir(v:null)'], 'E1174:')
392409
CheckDefExecFailure(['echo finddir("")'], 'E1142:')
393410
enddef
394411

395412
def Test_findfile()
396-
CheckDefExecFailure(['echo findfile(true)'], 'E928:')
397-
CheckDefExecFailure(['echo findfile(v:null)'], 'E928:')
413+
CheckDefExecFailure(['echo findfile(true)'], 'E1174:')
414+
CheckDefExecFailure(['echo findfile(v:null)'], 'E1174:')
398415
CheckDefExecFailure(['echo findfile("")'], 'E1142:')
399416
enddef
400417

@@ -421,9 +438,9 @@ def Test_fnamemodify()
421438
CheckDefSuccess(['echo fnamemodify("file", test_null_string())'])
422439
CheckDefSuccess(['echo fnamemodify("file", "")'])
423440

424-
CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E928:')
425-
CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E928:')
426-
CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E928:')
441+
CheckDefExecFailure(['echo fnamemodify(true, ":p")'], 'E1174: String required for argument 1')
442+
CheckDefExecFailure(['echo fnamemodify(v:null, ":p")'], 'E1174: String required for argument 1')
443+
CheckDefExecFailure(['echo fnamemodify("file", true)'], 'E1174: String required for argument 2')
427444
enddef
428445

429446
def Wrong_dict_key_type(items: list<number>): list<number>
@@ -524,32 +541,32 @@ def Test_getfperm()
524541
assert_equal('', getfperm(""))
525542
assert_equal('', getfperm(test_null_string()))
526543

527-
CheckDefExecFailure(['echo getfperm(true)'], 'E928:')
528-
CheckDefExecFailure(['echo getfperm(v:null)'], 'E928:')
544+
CheckDefExecFailure(['echo getfperm(true)'], 'E1174:')
545+
CheckDefExecFailure(['echo getfperm(v:null)'], 'E1174:')
529546
enddef
530547

531548
def Test_getfsize()
532549
assert_equal(-1, getfsize(""))
533550
assert_equal(-1, getfsize(test_null_string()))
534551

535-
CheckDefExecFailure(['echo getfsize(true)'], 'E928:')
536-
CheckDefExecFailure(['echo getfsize(v:null)'], 'E928:')
552+
CheckDefExecFailure(['echo getfsize(true)'], 'E1174:')
553+
CheckDefExecFailure(['echo getfsize(v:null)'], 'E1174:')
537554
enddef
538555

539556
def Test_getftime()
540557
assert_equal(-1, getftime(""))
541558
assert_equal(-1, getftime(test_null_string()))
542559

543-
CheckDefExecFailure(['echo getftime(true)'], 'E928:')
544-
CheckDefExecFailure(['echo getftime(v:null)'], 'E928:')
560+
CheckDefExecFailure(['echo getftime(true)'], 'E1174:')
561+
CheckDefExecFailure(['echo getftime(v:null)'], 'E1174:')
545562
enddef
546563

547564
def Test_getftype()
548565
assert_equal('', getftype(""))
549566
assert_equal('', getftype(test_null_string()))
550567

551-
CheckDefExecFailure(['echo getftype(true)'], 'E928:')
552-
CheckDefExecFailure(['echo getftype(v:null)'], 'E928:')
568+
CheckDefExecFailure(['echo getftype(true)'], 'E1174:')
569+
CheckDefExecFailure(['echo getftype(v:null)'], 'E1174:')
553570
enddef
554571

555572
def Test_getqflist_return_type()

src/typval.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,14 @@ tv_get_float(typval_T *varp)
344344
* Give an error and return FAIL unless "tv" is a string.
345345
*/
346346
int
347-
check_for_string(typval_T *tv)
347+
check_for_string(typval_T *tv, int arg)
348348
{
349349
if (tv->v_type != VAR_STRING)
350350
{
351-
emsg(_(e_stringreq));
351+
if (arg > 0)
352+
semsg(_(e_string_required_for_argument_nr), arg);
353+
else
354+
emsg(_(e_stringreq));
352355
return FAIL;
353356
}
354357
return OK;
@@ -358,13 +361,16 @@ check_for_string(typval_T *tv)
358361
* Give an error and return FAIL unless "tv" is a non-empty string.
359362
*/
360363
int
361-
check_for_nonempty_string(typval_T *tv)
364+
check_for_nonempty_string(typval_T *tv, int arg)
362365
{
363-
if (check_for_string(tv) == FAIL)
366+
if (check_for_string(tv, arg) == FAIL)
364367
return FAIL;
365368
if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL)
366369
{
367-
emsg(_(e_non_empty_string_required));
370+
if (arg > 0)
371+
semsg(_(e_non_empty_string_required_for_argument_nr), arg);
372+
else
373+
emsg(_(e_non_empty_string_required));
368374
return FAIL;
369375
}
370376
return OK;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2646,
753755
/**/
754756
2645,
755757
/**/

0 commit comments

Comments
 (0)