mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
eval: Use tv_is_func in place of ==VAR_FUNC||==VAR_PARTIAL
Also fixes same error as in vim/vim#1557
This commit is contained in:
parent
270a3889af
commit
43e9fad1c8
@ -2225,7 +2225,7 @@ static char_u *get_lval(char_u *const name, typval_T *const rettv,
|
|||||||
prevval = 0; // Avoid compiler warning.
|
prevval = 0; // Avoid compiler warning.
|
||||||
}
|
}
|
||||||
wrong = ((lp->ll_dict->dv_scope == VAR_DEF_SCOPE
|
wrong = ((lp->ll_dict->dv_scope == VAR_DEF_SCOPE
|
||||||
&& rettv->v_type == VAR_FUNC
|
&& tv_is_func(*rettv)
|
||||||
&& !var_check_func_name((const char *)key, lp->ll_di == NULL))
|
&& !var_check_func_name((const char *)key, lp->ll_di == NULL))
|
||||||
|| !valid_varname((const char *)key));
|
|| !valid_varname((const char *)key));
|
||||||
if (len != -1) {
|
if (len != -1) {
|
||||||
@ -3643,9 +3643,7 @@ static int eval4(char_u **arg, typval_T *rettv, int evaluate)
|
|||||||
n1 = !n1;
|
n1 = !n1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (rettv->v_type == VAR_FUNC || var2.v_type == VAR_FUNC
|
} else if (tv_is_func(*rettv) || tv_is_func(var2)) {
|
||||||
|| rettv->v_type == VAR_PARTIAL
|
|
||||||
|| var2.v_type == VAR_PARTIAL) {
|
|
||||||
if (type != TYPE_EQUAL && type != TYPE_NEQUAL) {
|
if (type != TYPE_EQUAL && type != TYPE_NEQUAL) {
|
||||||
EMSG(_("E694: Invalid operation for Funcrefs"));
|
EMSG(_("E694: Invalid operation for Funcrefs"));
|
||||||
tv_clear(rettv);
|
tv_clear(rettv);
|
||||||
@ -8957,8 +8955,7 @@ static void f_get(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
tv = &di->di_tv;
|
tv = &di->di_tv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (argvars[0].v_type == VAR_PARTIAL
|
} else if (tv_is_func(argvars[0])) {
|
||||||
|| argvars[0].v_type == VAR_FUNC) {
|
|
||||||
partial_T *pt;
|
partial_T *pt;
|
||||||
partial_T fref_pt;
|
partial_T fref_pt;
|
||||||
|
|
||||||
@ -15994,7 +15991,7 @@ static void f_substitute(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
const char *const flg = tv_get_string_buf_chk(&argvars[3], flagsbuf);
|
const char *const flg = tv_get_string_buf_chk(&argvars[3], flagsbuf);
|
||||||
|
|
||||||
typval_T *expr = NULL;
|
typval_T *expr = NULL;
|
||||||
if (argvars[2].v_type == VAR_FUNC || argvars[2].v_type == VAR_PARTIAL) {
|
if (tv_is_func(argvars[2])) {
|
||||||
expr = &argvars[2];
|
expr = &argvars[2];
|
||||||
} else {
|
} else {
|
||||||
sub = tv_get_string_buf_chk(&argvars[2], subbuf);
|
sub = tv_get_string_buf_chk(&argvars[2], subbuf);
|
||||||
@ -18229,8 +18226,7 @@ handle_subscript(
|
|||||||
while (ret == OK
|
while (ret == OK
|
||||||
&& (**arg == '['
|
&& (**arg == '['
|
||||||
|| (**arg == '.' && rettv->v_type == VAR_DICT)
|
|| (**arg == '.' && rettv->v_type == VAR_DICT)
|
||||||
|| (**arg == '(' && (!evaluate || rettv->v_type == VAR_FUNC
|
|| (**arg == '(' && (!evaluate || tv_is_func(*rettv))))
|
||||||
|| rettv->v_type == VAR_PARTIAL)))
|
|
||||||
&& !ascii_iswhite(*(*arg - 1))) {
|
&& !ascii_iswhite(*(*arg - 1))) {
|
||||||
if (**arg == '(') {
|
if (**arg == '(') {
|
||||||
partial_T *pt = NULL;
|
partial_T *pt = NULL;
|
||||||
@ -18286,9 +18282,7 @@ handle_subscript(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Turn "dict.Func" into a partial for "Func" bound to "dict".
|
// Turn "dict.Func" into a partial for "Func" bound to "dict".
|
||||||
if (selfdict != NULL
|
if (selfdict != NULL && tv_is_func(*rettv)) {
|
||||||
&& (rettv->v_type == VAR_FUNC
|
|
||||||
|| rettv->v_type == VAR_PARTIAL)) {
|
|
||||||
set_selfdict(rettv, selfdict);
|
set_selfdict(rettv, selfdict);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18794,8 +18788,7 @@ static void set_var(const char *name, const size_t name_len, typval_T *const tv,
|
|||||||
v = find_var_in_scoped_ht((const char *)name, name_len, true);
|
v = find_var_in_scoped_ht((const char *)name, name_len, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tv->v_type == VAR_FUNC || tv->v_type == VAR_PARTIAL)
|
if (tv_is_func(*tv) && !var_check_func_name(name, v == NULL)) {
|
||||||
&& !var_check_func_name(name, v == NULL)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19463,9 +19456,7 @@ void ex_function(exarg_T *eap)
|
|||||||
arg = name;
|
arg = name;
|
||||||
else
|
else
|
||||||
arg = fudi.fd_newkey;
|
arg = fudi.fd_newkey;
|
||||||
if (arg != NULL && (fudi.fd_di == NULL
|
if (arg != NULL && (fudi.fd_di == NULL || !tv_is_func(fudi.fd_di->di_tv))) {
|
||||||
|| (fudi.fd_di->di_tv.v_type != VAR_FUNC
|
|
||||||
&& fudi.fd_di->di_tv.v_type != VAR_PARTIAL))) {
|
|
||||||
int j = (*arg == K_SPECIAL) ? 3 : 0;
|
int j = (*arg == K_SPECIAL) ? 3 : 0;
|
||||||
while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j])
|
while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j])
|
||||||
: eval_isnamec(arg[j])))
|
: eval_isnamec(arg[j])))
|
||||||
|
@ -1250,8 +1250,7 @@ bool tv_dict_get_callback(dict_T *const d,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (di->di_tv.v_type != VAR_FUNC && di->di_tv.v_type != VAR_STRING
|
if (!tv_is_func(di->di_tv) && di->di_tv.v_type != VAR_STRING) {
|
||||||
&& di->di_tv.v_type != VAR_PARTIAL) {
|
|
||||||
emsgf(_("E6000: Argument is not a function or function name"));
|
emsgf(_("E6000: Argument is not a function or function name"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1418,7 +1417,7 @@ void tv_dict_extend(dict_T *const d1, dict_T *const d2,
|
|||||||
// Disallow replacing a builtin function in l: and g:.
|
// Disallow replacing a builtin function in l: and g:.
|
||||||
// Check the key to be valid when adding to any scope.
|
// Check the key to be valid when adding to any scope.
|
||||||
if (d1->dv_scope == VAR_DEF_SCOPE
|
if (d1->dv_scope == VAR_DEF_SCOPE
|
||||||
&& di2->di_tv.v_type == VAR_FUNC
|
&& tv_is_func(di2->di_tv)
|
||||||
&& !var_check_func_name((const char *)di2->di_key, di1 == NULL)) {
|
&& !var_check_func_name((const char *)di2->di_key, di1 == NULL)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2101,9 +2100,7 @@ bool tv_equal(typval_T *const tv1, typval_T *const tv2, const bool ic,
|
|||||||
// TODO(ZyX-I): Make this not recursive
|
// TODO(ZyX-I): Make this not recursive
|
||||||
static int recursive_cnt = 0; // Catch recursive loops.
|
static int recursive_cnt = 0; // Catch recursive loops.
|
||||||
|
|
||||||
if (!((tv1->v_type == VAR_FUNC || tv1->v_type == VAR_PARTIAL)
|
if (!(tv_is_func(*tv1) && tv_is_func(*tv2)) && tv1->v_type != tv2->v_type) {
|
||||||
&& (tv2->v_type == VAR_FUNC || tv2->v_type == VAR_PARTIAL))
|
|
||||||
&& tv1->v_type != tv2->v_type) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,6 +408,21 @@ static inline DictWatcher *tv_dict_watcher_node_data(QUEUE *q)
|
|||||||
return QUEUE_DATA(q, DictWatcher, node);
|
return QUEUE_DATA(q, DictWatcher, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool tv_is_func(const typval_T tv)
|
||||||
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_CONST;
|
||||||
|
|
||||||
|
/// Check whether given typval_T contains a function
|
||||||
|
///
|
||||||
|
/// That is, whether it contains VAR_FUNC or VAR_PARTIAL.
|
||||||
|
///
|
||||||
|
/// @param[in] tv Typval to check.
|
||||||
|
///
|
||||||
|
/// @return True if it is a function or a partial, false otherwise.
|
||||||
|
static inline bool tv_is_func(const typval_T tv)
|
||||||
|
{
|
||||||
|
return tv.v_type == VAR_FUNC || tv.v_type == VAR_PARTIAL;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "eval/typval.h.generated.h"
|
# include "eval/typval.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user