mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 18:36:30 +00:00
vim-patch:9.0.0335: checks for Dictionary argument often give a vague error (#23309)
Problem: Checks for Dictionary argument often give a vague error message.
Solution: Give a useful error message. (Yegappan Lakshmanan, closes vim/vim#11009)
04c4c5746e
Cherry-pick removal of E922 from docs from patch 9.0.1403.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -5357,8 +5357,7 @@ void common_function(typval_T *argvars, typval_T *rettv, bool is_funcref)
|
||||
arg_idx = 1;
|
||||
}
|
||||
if (dict_idx > 0) {
|
||||
if (argvars[dict_idx].v_type != VAR_DICT) {
|
||||
emsg(_("E922: expected a dict"));
|
||||
if (tv_check_for_dict_arg(argvars, dict_idx) == FAIL) {
|
||||
xfree(name);
|
||||
goto theend;
|
||||
}
|
||||
@@ -8726,7 +8725,7 @@ int typval_compare(typval_T *typ1, typval_T *typ2, exprtype_T type, bool ic)
|
||||
const bool type_is = type == EXPR_IS || type == EXPR_ISNOT;
|
||||
|
||||
if (type_is && typ1->v_type != typ2->v_type) {
|
||||
// For "is" a different type always means false, for "notis"
|
||||
// For "is" a different type always means false, for "isnot"
|
||||
// it means true.
|
||||
n1 = type == EXPR_ISNOT;
|
||||
} else if (typ1->v_type == VAR_BLOB || typ2->v_type == VAR_BLOB) {
|
||||
|
@@ -597,8 +597,7 @@ static void f_call(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
|
||||
dict_T *selfdict = NULL;
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
if (argvars[2].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 2) == FAIL) {
|
||||
if (owned) {
|
||||
func_unref(func);
|
||||
}
|
||||
@@ -7359,8 +7358,7 @@ static void f_setcharpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
|
||||
static void f_setcharsearch(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
if (argvars[0].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 0) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7631,8 +7629,7 @@ static void f_settagstack(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
|
||||
// second argument: dict with items to set in the tag stack
|
||||
if (argvars[1].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 1) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict_T *d = argvars[1].vval.v_dict;
|
||||
@@ -8987,11 +8984,10 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
dict_T *dict = argvars[2].vval.v_dict;
|
||||
if (argvars[2].v_type != VAR_DICT || dict == NULL) {
|
||||
semsg(_(e_invarg2), tv_get_string(&argvars[2]));
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 2) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict_T *dict = argvars[2].vval.v_dict;
|
||||
dictitem_T *const di = tv_dict_find(dict, S_LEN("repeat"));
|
||||
if (di != NULL) {
|
||||
repeat = (int)tv_get_number(&di->di_tv);
|
||||
|
@@ -60,6 +60,8 @@ static const char e_invalid_value_for_blob_nr[]
|
||||
= N_("E1239: Invalid value for blob: %d");
|
||||
static const char e_string_or_function_required_for_argument_nr[]
|
||||
= N_("E1256: String or function required for argument %d");
|
||||
static const char e_non_null_dict_required_for_argument_nr[]
|
||||
= N_("E1297: Non-NULL Dictionary required for argument %d");
|
||||
|
||||
bool tv_in_free_unref_items = false;
|
||||
|
||||
@@ -1232,8 +1234,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
|
||||
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
// optional third argument: {dict}
|
||||
if (argvars[2].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 2) == FAIL) {
|
||||
goto theend;
|
||||
}
|
||||
info.item_compare_selfdict = argvars[2].vval.v_dict;
|
||||
@@ -2993,10 +2994,10 @@ void f_values(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
/// "has_key()" function
|
||||
void f_has_key(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
if (argvars[0].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 0) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (argvars[0].vval.v_dict == NULL) {
|
||||
return;
|
||||
}
|
||||
@@ -4051,6 +4052,20 @@ int tv_check_for_dict_arg(const typval_T *const args, const int idx)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Give an error and return FAIL unless "args[idx]" is a non-NULL dict.
|
||||
int tv_check_for_nonnull_dict_arg(const typval_T *const args, const int idx)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
||||
{
|
||||
if (tv_check_for_dict_arg(args, idx) == FAIL) {
|
||||
return FAIL;
|
||||
}
|
||||
if (args[idx].vval.v_dict == NULL) {
|
||||
semsg(_(e_non_null_dict_required_for_argument_nr), idx + 1);
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Check for an optional dict argument at "idx"
|
||||
int tv_check_for_opt_dict_arg(const typval_T *const args, const int idx)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
||||
|
@@ -651,8 +651,7 @@ void f_win_splitmove(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
dict_T *d;
|
||||
dictitem_T *di;
|
||||
|
||||
if (argvars[2].v_type != VAR_DICT || argvars[2].vval.v_dict == NULL) {
|
||||
emsg(_(e_invarg));
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 2) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -796,51 +795,50 @@ void f_winrestcmd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
/// "winrestview()" function
|
||||
void f_winrestview(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
dict_T *dict = argvars[0].vval.v_dict;
|
||||
|
||||
if (argvars[0].v_type != VAR_DICT || dict == NULL) {
|
||||
emsg(_(e_invarg));
|
||||
} else {
|
||||
dictitem_T *di;
|
||||
if ((di = tv_dict_find(dict, S_LEN("lnum"))) != NULL) {
|
||||
curwin->w_cursor.lnum = (linenr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("col"))) != NULL) {
|
||||
curwin->w_cursor.col = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("coladd"))) != NULL) {
|
||||
curwin->w_cursor.coladd = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("curswant"))) != NULL) {
|
||||
curwin->w_curswant = (colnr_T)tv_get_number(&di->di_tv);
|
||||
curwin->w_set_curswant = false;
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("topline"))) != NULL) {
|
||||
set_topline(curwin, (linenr_T)tv_get_number(&di->di_tv));
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("topfill"))) != NULL) {
|
||||
curwin->w_topfill = (int)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("leftcol"))) != NULL) {
|
||||
curwin->w_leftcol = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("skipcol"))) != NULL) {
|
||||
curwin->w_skipcol = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
|
||||
check_cursor();
|
||||
win_new_height(curwin, curwin->w_height);
|
||||
win_new_width(curwin, curwin->w_width);
|
||||
changed_window_setting();
|
||||
|
||||
if (curwin->w_topline <= 0) {
|
||||
curwin->w_topline = 1;
|
||||
}
|
||||
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
|
||||
curwin->w_topline = curbuf->b_ml.ml_line_count;
|
||||
}
|
||||
check_topfill(curwin, true);
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 0) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
dict_T *dict = argvars[0].vval.v_dict;
|
||||
dictitem_T *di;
|
||||
if ((di = tv_dict_find(dict, S_LEN("lnum"))) != NULL) {
|
||||
curwin->w_cursor.lnum = (linenr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("col"))) != NULL) {
|
||||
curwin->w_cursor.col = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("coladd"))) != NULL) {
|
||||
curwin->w_cursor.coladd = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("curswant"))) != NULL) {
|
||||
curwin->w_curswant = (colnr_T)tv_get_number(&di->di_tv);
|
||||
curwin->w_set_curswant = false;
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("topline"))) != NULL) {
|
||||
set_topline(curwin, (linenr_T)tv_get_number(&di->di_tv));
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("topfill"))) != NULL) {
|
||||
curwin->w_topfill = (int)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("leftcol"))) != NULL) {
|
||||
curwin->w_leftcol = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
if ((di = tv_dict_find(dict, S_LEN("skipcol"))) != NULL) {
|
||||
curwin->w_skipcol = (colnr_T)tv_get_number(&di->di_tv);
|
||||
}
|
||||
|
||||
check_cursor();
|
||||
win_new_height(curwin, curwin->w_height);
|
||||
win_new_width(curwin, curwin->w_width);
|
||||
changed_window_setting();
|
||||
|
||||
if (curwin->w_topline <= 0) {
|
||||
curwin->w_topline = 1;
|
||||
}
|
||||
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
|
||||
curwin->w_topline = curbuf->b_ml.ml_line_count;
|
||||
}
|
||||
check_topfill(curwin, true);
|
||||
}
|
||||
|
||||
/// "winsaveview()" function
|
||||
|
@@ -2204,8 +2204,7 @@ void f_mapset(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
const int mode = get_map_mode((char **)&which, 0);
|
||||
const bool is_abbr = tv_get_number(&argvars[1]) != 0;
|
||||
|
||||
if (argvars[2].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 2) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict_T *d = argvars[2].vval.v_dict;
|
||||
|
@@ -2772,8 +2772,7 @@ void f_searchcount(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
dictitem_T *di;
|
||||
bool error = false;
|
||||
|
||||
if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 0) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict = argvars[0].vval.v_dict;
|
||||
@@ -3348,8 +3347,7 @@ static void do_fuzzymatch(const typval_T *const argvars, typval_T *const rettv,
|
||||
bool matchseq = false;
|
||||
long max_matches = 0;
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
if (argvars[2].v_type != VAR_DICT || argvars[2].vval.v_dict == NULL) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 2) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -2017,8 +2017,7 @@ void f_sign_define(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
return;
|
||||
}
|
||||
|
||||
if (argvars[1].v_type != VAR_UNKNOWN && argvars[1].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_opt_dict_arg(argvars, 1) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2061,12 +2060,10 @@ void f_sign_getplaced(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
|
||||
if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||
dict_T *dict;
|
||||
if (argvars[1].v_type != VAR_DICT
|
||||
|| ((dict = argvars[1].vval.v_dict) == NULL)) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 1) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict_T *dict = argvars[1].vval.v_dict;
|
||||
if ((di = tv_dict_find(dict, "lnum", -1)) != NULL) {
|
||||
// get signs placed at this line
|
||||
lnum = (linenr_T)tv_get_number_chk(&di->di_tv, ¬anum);
|
||||
@@ -2263,11 +2260,11 @@ void f_sign_place(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
|
||||
rettv->vval.v_number = -1;
|
||||
|
||||
if (argvars[4].v_type != VAR_UNKNOWN
|
||||
&& (argvars[4].v_type != VAR_DICT
|
||||
|| ((dict = argvars[4].vval.v_dict) == NULL))) {
|
||||
emsg(_(e_dictreq));
|
||||
return;
|
||||
if (argvars[4].v_type != VAR_UNKNOWN) {
|
||||
if (tv_check_for_nonnull_dict_arg(argvars, 4) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict = argvars[4].vval.v_dict;
|
||||
}
|
||||
|
||||
rettv->vval.v_number = sign_place_from_dict(&argvars[0], &argvars[1], &argvars[2], &argvars[3],
|
||||
@@ -2415,8 +2412,7 @@ void f_sign_unplace(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
|
||||
if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||
if (argvars[1].v_type != VAR_DICT) {
|
||||
emsg(_(e_dictreq));
|
||||
if (tv_check_for_dict_arg(argvars, 1) == FAIL) {
|
||||
return;
|
||||
}
|
||||
dict = argvars[1].vval.v_dict;
|
||||
|
Reference in New Issue
Block a user