mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 18:06:30 +00:00
vim-patch:9.0.1540: reverse() on string doesn't work in compiled function
Problem: reverse() on string doesn't work in compiled function.
Solution: Accept string in argument type check. (Yegappan Lakshmanan,
closes vim/vim#12377)
f9dc278946
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -6199,6 +6199,10 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
/// "reverse({list})" function
|
||||
static void f_reverse(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
if (tv_check_for_string_or_list_or_blob_arg(argvars, 0) == FAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (argvars[0].v_type == VAR_BLOB) {
|
||||
blob_T *const b = argvars[0].vval.v_blob;
|
||||
const int len = tv_blob_len(b);
|
||||
@@ -6216,9 +6220,7 @@ static void f_reverse(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
} else {
|
||||
rettv->vval.v_string = NULL;
|
||||
}
|
||||
} else if (argvars[0].v_type != VAR_LIST) {
|
||||
semsg(_(e_listblobarg), "reverse()");
|
||||
} else {
|
||||
} else if (argvars[0].v_type == VAR_LIST) {
|
||||
list_T *const l = argvars[0].vval.v_list;
|
||||
if (!value_check_lock(tv_list_locked(l), N_("reverse() argument"),
|
||||
TV_TRANSLATE)) {
|
||||
|
@@ -81,6 +81,8 @@ static const char e_blob_required_for_argument_nr[]
|
||||
= N_("E1238: Blob required for argument %d");
|
||||
static const char e_invalid_value_for_blob_nr[]
|
||||
= N_("E1239: Invalid value for blob: %d");
|
||||
static const char e_string_list_or_blob_required_for_argument_nr[]
|
||||
= N_("E1252: String, List or Blob required for argument %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[]
|
||||
@@ -4350,7 +4352,20 @@ int tv_check_for_string_or_list_arg(const typval_T *const args, const int idx)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Check for an optional string or list argument at 'idx'
|
||||
/// Give an error and return FAIL unless "args[idx]" is a string, a list or a blob.
|
||||
int tv_check_for_string_or_list_or_blob_arg(const typval_T *const args, const int idx)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
||||
{
|
||||
if (args[idx].v_type != VAR_STRING
|
||||
&& args[idx].v_type != VAR_LIST
|
||||
&& args[idx].v_type != VAR_BLOB) {
|
||||
semsg(_(e_string_list_or_blob_required_for_argument_nr), idx + 1);
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/// Check for an optional string or list argument at "idx"
|
||||
int tv_check_for_opt_string_or_list_arg(const typval_T *const args, const int idx)
|
||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
|
||||
{
|
||||
|
Reference in New Issue
Block a user