mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.1522: some functions give two error messages
Problem: Some functions give two error messages.
Solution: Do not give a second error message. (closes vim/vim#12352)
e4098457ab
It seems that tv_get_bool() is actually not exactly the same as
tv_get_number(), so change it to a function instead.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
parent
4ecf6fdfd8
commit
d745433817
@ -2166,6 +2166,16 @@ varnumber_T tv_dict_get_number_def(const dict_T *const d, const char *const key,
|
||||
return tv_get_number(&di->di_tv);
|
||||
}
|
||||
|
||||
varnumber_T tv_dict_get_bool(const dict_T *const d, const char *const key, const int def)
|
||||
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
dictitem_T *const di = tv_dict_find(d, key, -1);
|
||||
if (di == NULL) {
|
||||
return def;
|
||||
}
|
||||
return tv_get_bool(&di->di_tv);
|
||||
}
|
||||
|
||||
/// Converts a dict to an environment
|
||||
char **tv_dict_to_env(dict_T *denv)
|
||||
{
|
||||
@ -4049,6 +4059,18 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error)
|
||||
return (ret_error == NULL ? -1 : 0);
|
||||
}
|
||||
|
||||
varnumber_T tv_get_bool(const typval_T *const tv)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
||||
{
|
||||
return tv_get_number_chk(tv, NULL);
|
||||
}
|
||||
|
||||
varnumber_T tv_get_bool_chk(const typval_T *const tv, bool *const ret_error)
|
||||
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
|
||||
{
|
||||
return tv_get_number_chk(tv, ret_error);
|
||||
}
|
||||
|
||||
/// Get the line number from VimL object
|
||||
///
|
||||
/// @param[in] tv Object to get value from. Is expected to be a number or
|
||||
|
@ -567,8 +567,4 @@ EXTERN const size_t kTVTranslate INIT(= TV_TRANSLATE);
|
||||
# include "eval/typval.h.generated.h"
|
||||
#endif
|
||||
|
||||
#define tv_get_bool tv_get_number
|
||||
#define tv_get_bool_chk tv_get_number_chk
|
||||
#define tv_dict_get_bool tv_dict_get_number_def
|
||||
|
||||
#endif // NVIM_EVAL_TYPVAL_H
|
||||
|
@ -1502,7 +1502,8 @@ char *strrep(const char *src, const char *what, const char *rep)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
|
||||
/// Implementation of "byteidx()" and "byteidxcomp()" functions
|
||||
static void byteidx_common(typval_T *argvars, typval_T *rettv, int comp)
|
||||
{
|
||||
rettv->vval.v_number = -1;
|
||||
|
||||
@ -1516,7 +1517,9 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
|
||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||
utf16idx = tv_get_bool(&argvars[2]);
|
||||
if (utf16idx < 0 || utf16idx > 1) {
|
||||
semsg(_(e_using_number_as_bool_nr), utf16idx);
|
||||
if (utf16idx != -1) {
|
||||
semsg(_(e_using_number_as_bool_nr), utf16idx);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1550,13 +1553,13 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
|
||||
/// "byteidx()" function
|
||||
void f_byteidx(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
byteidx(argvars, rettv, false);
|
||||
byteidx_common(argvars, rettv, false);
|
||||
}
|
||||
|
||||
/// "byteidxcomp()" function
|
||||
void f_byteidxcomp(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
byteidx(argvars, rettv, true);
|
||||
byteidx_common(argvars, rettv, true);
|
||||
}
|
||||
|
||||
/// "charidx()" function
|
||||
@ -1770,7 +1773,9 @@ void f_strchars(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
skipcc = (int)tv_get_bool(&argvars[1]);
|
||||
}
|
||||
if (skipcc < 0 || skipcc > 1) {
|
||||
semsg(_(e_using_number_as_bool_nr), skipcc);
|
||||
if (skipcc != -1) {
|
||||
semsg(_(e_using_number_as_bool_nr), skipcc);
|
||||
}
|
||||
} else {
|
||||
strchar_common(argvars, rettv, skipcc);
|
||||
}
|
||||
@ -1842,7 +1847,9 @@ void f_strcharpart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
&& argvars[3].v_type != VAR_UNKNOWN) {
|
||||
skipcc = tv_get_bool(&argvars[3]);
|
||||
if (skipcc < 0 || skipcc > 1) {
|
||||
semsg(_(e_using_number_as_bool_nr), skipcc);
|
||||
if (skipcc != -1) {
|
||||
semsg(_(e_using_number_as_bool_nr), skipcc);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,8 @@ func Test_strcharpart()
|
||||
call assert_equal('edit', "editor"[-10 : 3])
|
||||
END
|
||||
call CheckLegacyAndVim9Success(lines)
|
||||
|
||||
call assert_fails('echo strcharpart("", 0, 0, {})', ['E728:', 'E728:'])
|
||||
endfunc
|
||||
|
||||
func Test_getreg_empty_list()
|
||||
|
@ -1096,6 +1096,7 @@ func Test_byteidx()
|
||||
" error cases
|
||||
call assert_fails("call byteidx([], 0)", 'E730:')
|
||||
call assert_fails("call byteidx('abc', [])", 'E745:')
|
||||
call assert_fails("call byteidx('abc', 0, {})", ['E728:', 'E728:'])
|
||||
endfunc
|
||||
|
||||
" Test for byteidxcomp() using a character index
|
||||
@ -1135,6 +1136,7 @@ func Test_byteidxcomp()
|
||||
" error cases
|
||||
call assert_fails("call byteidxcomp([], 0)", 'E730:')
|
||||
call assert_fails("call byteidxcomp('abc', [])", 'E745:')
|
||||
call assert_fails("call byteidxcomp('abc', 0, {})", ['E728:', 'E728:'])
|
||||
endfunc
|
||||
|
||||
" Test for byteidx() using a UTF-16 index
|
||||
@ -1495,6 +1497,7 @@ func Test_utf16idx_from_charidx()
|
||||
" error cases
|
||||
call assert_equal(-1, utf16idx(v:_null_string, 0, v:true, v:true))
|
||||
call assert_fails('let l = utf16idx("ab", 0, v:false, [])', 'E1212:')
|
||||
call assert_fails('echo strchars("", {})', ['E728:', 'E728:'])
|
||||
endfunc
|
||||
|
||||
" Test for strutf16len()
|
||||
|
Loading…
Reference in New Issue
Block a user