Skip to content

Commit

Permalink
patch 9.0.0359: error message for wrong argument type is not specific
Browse files Browse the repository at this point in the history
Problem:    Error message for wrong argument type is not specific.
Solution:   Include more information in the error. (Yegappan Lakshmanan,
            closes #11037)
  • Loading branch information
yegappan authored and brammool committed Sep 2, 2022
1 parent 1191672 commit 8deb2b3
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 193 deletions.
5 changes: 1 addition & 4 deletions src/blob.c
Expand Up @@ -667,11 +667,8 @@ blob_reduce(
initial.vval.v_number = blob_get(b, 0);
i = 1;
}
else if (argvars[2].v_type != VAR_NUMBER)
{
emsg(_(e_number_expected));
else if (check_for_number_arg(argvars, 2) == FAIL)
return;
}
else
{
initial = argvars[2];
Expand Down
5 changes: 1 addition & 4 deletions src/cmdexpand.c
Expand Up @@ -3679,11 +3679,8 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
return;

pat = tv_get_string(&argvars[0]);
if (argvars[1].v_type != VAR_STRING)
{
semsg(_(e_invalid_argument_str), "type must be a string");
if (check_for_string_arg(argvars, 1) == FAIL)
return;
}
type = tv_get_string(&argvars[1]);

if (argvars[2].v_type != VAR_UNKNOWN)
Expand Down
35 changes: 9 additions & 26 deletions src/evalfunc.c
Expand Up @@ -3607,17 +3607,13 @@ f_deepcopy(typval_T *argvars, typval_T *rettv)
{
varnumber_T noref = 0;

if (in_vim9script()
&& (check_for_opt_bool_arg(argvars, 1) == FAIL))
if (check_for_opt_bool_arg(argvars, 1) == FAIL)
return;

if (argvars[1].v_type != VAR_UNKNOWN)
noref = tv_get_bool_chk(&argvars[1], NULL);
if (noref < 0 || noref > 1)
semsg(_(e_using_number_as_bool_nr), noref);
else
item_copy(&argvars[0], rettv, TRUE, TRUE,
noref == 0 ? get_copyID() : 0);

item_copy(&argvars[0], rettv, TRUE, TRUE, noref == 0 ? get_copyID() : 0);
}

/*
Expand Down Expand Up @@ -5257,21 +5253,11 @@ f_gettagstack(typval_T *argvars, typval_T *rettv)
static void
f_gettext(typval_T *argvars, typval_T *rettv)
{
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
if (check_for_nonempty_string_arg(argvars, 0) == FAIL)
return;

if (argvars[0].v_type != VAR_STRING
|| argvars[0].vval.v_string == NULL
|| *argvars[0].vval.v_string == NUL)
{
semsg(_(e_invalid_argument_str), tv_get_string(&argvars[0]));
}
else
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = vim_strsave(
(char_u *)_(argvars[0].vval.v_string));
}
rettv->v_type = VAR_STRING;
rettv->vval.v_string = vim_strsave((char_u *)_(argvars[0].vval.v_string));
}

// for VIM_VERSION_ defines
Expand Down Expand Up @@ -9641,7 +9627,9 @@ f_settagstack(typval_T *argvars, typval_T *rettv)
// default is to replace the stack.
if (argvars[2].v_type == VAR_UNKNOWN)
action = 'r';
else if (argvars[2].v_type == VAR_STRING)
else if (check_for_string_arg(argvars, 2) == FAIL)
return;
else
{
char_u *actstr;
actstr = tv_get_string_chk(&argvars[2]);
Expand All @@ -9656,11 +9644,6 @@ f_settagstack(typval_T *argvars, typval_T *rettv)
return;
}
}
else
{
emsg(_(e_string_required));
return;
}

if (set_tagstack(wp, d, action) == OK)
rettv->vval.v_number = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/popupwin.c
Expand Up @@ -2769,9 +2769,7 @@ f_popup_settext(typval_T *argvars, typval_T *rettv UNUSED)
wp = find_popup_win(id);
if (wp != NULL)
{
if (argvars[1].v_type != VAR_STRING && argvars[1].v_type != VAR_LIST)
semsg(_(e_invalid_argument_str), tv_get_string(&argvars[1]));
else
if (check_for_string_or_list_arg(argvars, 1) != FAIL)
{
popup_set_buffer_text(wp->w_buffer, argvars[1]);
redraw_win_later(wp, UPD_NOT_VALID);
Expand Down
13 changes: 1 addition & 12 deletions src/sign.c
Expand Up @@ -2849,23 +2849,12 @@ f_sign_unplace(typval_T *argvars, typval_T *rettv)

rettv->vval.v_number = -1;

if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
if ((check_for_string_arg(argvars, 0) == FAIL
|| check_for_opt_dict_arg(argvars, 1) == FAIL))
return;

if (argvars[0].v_type != VAR_STRING)
{
emsg(_(e_invalid_argument));
return;
}

if (argvars[1].v_type != VAR_UNKNOWN)
{
if (check_for_dict_arg(argvars, 1) == FAIL)
return;
dict = argvars[1].vval.v_dict;
}

rettv->vval.v_number = sign_unplace_from_dict(&argvars[0], dict);
}
Expand Down
22 changes: 3 additions & 19 deletions src/strings.c
Expand Up @@ -960,11 +960,8 @@ string_reduce(
return;
p += STRLEN(rettv->vval.v_string);
}
else if (argvars[2].v_type != VAR_STRING)
{
semsg(_(e_string_expected_for_argument_nr), 3);
else if (check_for_string_arg(argvars, 2) == FAIL)
return;
}
else
copy_tv(&argvars[2], rettv);

Expand Down Expand Up @@ -1047,21 +1044,11 @@ f_charidx(typval_T *argvars, typval_T *rettv)

rettv->vval.v_number = -1;

if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
if ((check_for_string_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL
|| check_for_opt_bool_arg(argvars, 2) == FAIL))
return;

if (argvars[0].v_type != VAR_STRING || argvars[1].v_type != VAR_NUMBER
|| (argvars[2].v_type != VAR_UNKNOWN
&& argvars[2].v_type != VAR_NUMBER
&& argvars[2].v_type != VAR_BOOL))
{
emsg(_(e_invalid_argument));
return;
}

str = tv_get_string_chk(&argvars[0]);
idx = tv_get_number_chk(&argvars[1], NULL);
if (str == NULL || idx < 0)
Expand Down Expand Up @@ -1783,11 +1770,8 @@ f_trim(typval_T *argvars, typval_T *rettv)
if (head == NULL)
return;

if (argvars[1].v_type != VAR_UNKNOWN && argvars[1].v_type != VAR_STRING)
{
semsg(_(e_invalid_argument_str), tv_get_string(&argvars[1]));
if (check_for_opt_string_arg(argvars, 1) == FAIL)
return;
}

if (argvars[1].v_type == VAR_STRING)
{
Expand Down
2 changes: 1 addition & 1 deletion src/testdir/test_assert.vim
Expand Up @@ -368,7 +368,7 @@ func Test_override()
eval 1->test_override('redraw')
call test_override('ALL', 0)
call assert_fails("call test_override('xxx', 1)", 'E475:')
call assert_fails("call test_override('redraw', 'yes')", 'E474:')
call assert_fails("call test_override('redraw', 'yes')", 'E1210:')
endfunc

func Test_mouse_position()
Expand Down
2 changes: 1 addition & 1 deletion src/testdir/test_cmdline.vim
Expand Up @@ -605,7 +605,7 @@ func Test_getcompletion()

call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E871:')
call assert_fails('call getcompletion("", "burp")', 'E475:')
call assert_fails('call getcompletion("abc", [])', 'E475:')
call assert_fails('call getcompletion("abc", [])', 'E1174:')
endfunc

" Test for getcompletion() with "fuzzy" in 'wildoptions'
Expand Down
14 changes: 7 additions & 7 deletions src/testdir/test_functions.vim
Expand Up @@ -1247,11 +1247,11 @@ func Test_charidx()
call assert_equal(-1, charidx(a, 8, 1))
call assert_equal(-1, charidx('', 0, 1))

call assert_fails('let x = charidx([], 1)', 'E474:')
call assert_fails('let x = charidx("abc", [])', 'E474:')
call assert_fails('let x = charidx("abc", 1, [])', 'E474:')
call assert_fails('let x = charidx("abc", 1, -1)', 'E1023:')
call assert_fails('let x = charidx("abc", 1, 2)', 'E1023:')
call assert_fails('let x = charidx([], 1)', 'E1174:')
call assert_fails('let x = charidx("abc", [])', 'E1210:')
call assert_fails('let x = charidx("abc", 1, [])', 'E1212:')
call assert_fails('let x = charidx("abc", 1, -1)', 'E1212:')
call assert_fails('let x = charidx("abc", 1, 2)', 'E1212:')
endfunc

func Test_count()
Expand Down Expand Up @@ -1738,7 +1738,7 @@ func Test_trim()
call assert_fails('eval trim(" vim ", " ", [])', 'E745:')
call assert_fails('eval trim(" vim ", " ", -1)', 'E475:')
call assert_fails('eval trim(" vim ", " ", 3)', 'E475:')
call assert_fails('eval trim(" vim ", 0)', 'E475:')
call assert_fails('eval trim(" vim ", 0)', 'E1174:')

let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '')
call assert_equal("x", trim(chars . "x" . chars))
Expand Down Expand Up @@ -2913,7 +2913,7 @@ endfunc

" Test for gettext()
func Test_gettext()
call assert_fails('call gettext(1)', 'E475:')
call assert_fails('call gettext(1)', 'E1174:')
endfunc

func Test_builtin_check()
Expand Down
12 changes: 6 additions & 6 deletions src/testdir/test_listdict.vim
Expand Up @@ -568,7 +568,7 @@ func Test_dict_deepcopy()
END
call v9.CheckLegacyAndVim9Success(lines)

call assert_fails("call deepcopy([1, 2], 2)", 'E1023:')
call assert_fails("call deepcopy([1, 2], 2)", 'E1212:')
endfunc

" Locked variables
Expand Down Expand Up @@ -1044,16 +1044,16 @@ func Test_reduce()
call assert_fails("call reduce({}, { acc, val -> acc + val }, 1)", 'E1098:')
call assert_fails("call reduce(0, { acc, val -> acc + val }, 1)", 'E1098:')
call assert_fails("call reduce([1, 2], 'Xdoes_not_exist')", 'E117:')
call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E39:')
call assert_fails("echo reduce(0z01, { acc, val -> 2 * acc + val }, '')", 'E1210:')

call assert_fails("vim9 reduce(0, (acc, val) => (acc .. val), '')", 'E1252:')
call assert_fails("vim9 reduce({}, (acc, val) => (acc .. val), '')", 'E1252:')
call assert_fails("vim9 reduce(0.1, (acc, val) => (acc .. val), '')", 'E1252:')
call assert_fails("vim9 reduce(function('tr'), (acc, val) => (acc .. val), '')", 'E1252:')
call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E1253:')
call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1253:')
call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1253:')
call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1253:')
call assert_fails("call reduce('', { acc, val -> acc + val }, 1)", 'E1174:')
call assert_fails("call reduce('', { acc, val -> acc + val }, {})", 'E1174:')
call assert_fails("call reduce('', { acc, val -> acc + val }, 0.1)", 'E1174:')
call assert_fails("call reduce('', { acc, val -> acc + val }, function('tr'))", 'E1174:')
call assert_fails("call reduce('abc', { a, v -> a10}, '')", 'E121:')
call assert_fails("call reduce(0z0102, { a, v -> a10}, 1)", 'E121:')
call assert_fails("call reduce([1, 2], { a, v -> a10}, '')", 'E121:')
Expand Down
2 changes: 1 addition & 1 deletion src/testdir/test_signs.vim
Expand Up @@ -686,7 +686,7 @@ func Test_sign_group()
call assert_equal([], sign_getplaced(bnum, {'group' : '*'})[0].signs)

" Error case
call assert_fails("call sign_unplace({})", 'E474:')
call assert_fails("call sign_unplace({})", 'E1174:')

" Place a sign in the global group and try to delete it using a group
call assert_equal(5, sign_place(5, '', 'sign1', bnum, {'lnum' : 10}))
Expand Down
2 changes: 1 addition & 1 deletion src/testdir/test_tagjump.vim
Expand Up @@ -405,7 +405,7 @@ func Test_getsettagstack()
call assert_equal(-1, settagstack(100, {'items' : []}))
call assert_fails('call settagstack(1, [1, 10])', 'E1206:')
call assert_fails("call settagstack(1, {'items' : 10})", 'E714:')
call assert_fails("call settagstack(1, {'items' : []}, 10)", 'E928:')
call assert_fails("call settagstack(1, {'items' : []}, 10)", 'E1174:')
call assert_fails("call settagstack(1, {'items' : []}, 'b')", 'E962:')
call assert_equal(-1, settagstack(0, test_null_dict()))

Expand Down
4 changes: 2 additions & 2 deletions src/testdir/test_timers.vim
Expand Up @@ -116,7 +116,7 @@ func Test_timer_info()
call timer_stop(id)
call assert_equal([], timer_info(id))

call assert_fails('call timer_info("abc")', 'E39:')
call assert_fails('call timer_info("abc")', 'E1210:')

" check repeat count inside the callback
let g:timer_repeat = []
Expand Down Expand Up @@ -267,7 +267,7 @@ func Test_timer_errors()

call assert_fails('call timer_start(100, "MyHandler", "abc")', 'E1206:')
call assert_fails('call timer_start(100, [])', 'E921:')
call assert_fails('call timer_stop("abc")', 'E39:')
call assert_fails('call timer_stop("abc")', 'E1210:')
endfunc

func FuncWithCaughtError(timer)
Expand Down
4 changes: 2 additions & 2 deletions src/testdir/test_vim9_builtin.vim
Expand Up @@ -1961,9 +1961,9 @@ enddef

def Test_gettext()
v9.CheckDefAndScriptFailure(['gettext(10)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
v9.CheckDefExecAndScriptFailure(['gettext("")'], 'E475: Invalid argument')
v9.CheckDefExecAndScriptFailure(['gettext("")'], 'E1175: Non-empty string required for argument 1')
assert_equal('abc', gettext("abc"))
assert_fails('gettext("")', 'E475:')
assert_fails('gettext("")', 'E1175:')
enddef

def Test_getwininfo()
Expand Down

0 comments on commit 8deb2b3

Please sign in to comment.