summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-17 22:15:47 +0200
committerChristian Brabandt <cb@256bit.org>2023-08-17 22:15:47 +0200
commitad0c442f1fcc6fe9c433777ee3e5b9e6addc6d69 (patch)
tree60279c75b0d60c44f602a980717db10239fcbbe4 /src/eval.c
parent4f389e7c0fe7dfeccfa512a72fa36f9028d57159 (diff)
patch 9.0.1723: Fix regression in {func} argument of reduce()v9.0.1723
Problem: Fix regression in {func} argument of reduce() Solution: pass function name as string again Before patch 9.0.0548, passing a string as {func} argument of reduce() is treated as a function name, but after patch 9.0.0548 it is treated as an expression instead, which is useless as reduce() doesn't set any v: variables. This PR restores the behavior of {func} before that patch. Also correct an emsg() call, as e_string_list_or_blob_required doesn't contain format specifiers. closes: #12824 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/eval.c b/src/eval.c
index 8660a25d50..cfcec9bac0 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -252,12 +252,14 @@ eval_expr_get_funccal(typval_T *expr, typval_T *rettv)
/*
* Evaluate an expression, which can be a function, partial or string.
* Pass arguments "argv[argc]".
+ * If "want_func" is TRUE treat a string as a function name, not an expression.
* "fc_arg" is from eval_expr_get_funccal() or NULL;
* Return the result in "rettv" and OK or FAIL.
*/
int
eval_expr_typval(
typval_T *expr,
+ int want_func,
typval_T *argv,
int argc,
funccall_T *fc_arg,
@@ -267,17 +269,7 @@ eval_expr_typval(
char_u buf[NUMBUFLEN];
funcexe_T funcexe;
- if (expr->v_type == VAR_FUNC)
- {
- s = expr->vval.v_string;
- if (s == NULL || *s == NUL)
- return FAIL;
- CLEAR_FIELD(funcexe);
- funcexe.fe_evaluate = TRUE;
- if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
- return FAIL;
- }
- else if (expr->v_type == VAR_PARTIAL)
+ if (expr->v_type == VAR_PARTIAL)
{
partial_T *partial = expr->vval.v_partial;
@@ -318,6 +310,18 @@ eval_expr_typval(
{
return exe_typval_instr(expr, rettv);
}
+ else if (expr->v_type == VAR_FUNC || want_func)
+ {
+ s = expr->v_type == VAR_FUNC
+ ? expr->vval.v_string
+ : tv_get_string_buf_chk_strict(expr, buf, in_vim9script());
+ if (s == NULL || *s == NUL)
+ return FAIL;
+ CLEAR_FIELD(funcexe);
+ funcexe.fe_evaluate = TRUE;
+ if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
+ return FAIL;
+ }
else
{
s = tv_get_string_buf_chk_strict(expr, buf, in_vim9script());
@@ -346,7 +350,7 @@ eval_expr_to_bool(typval_T *expr, int *error)
typval_T rettv;
int res;
- if (eval_expr_typval(expr, NULL, 0, NULL, &rettv) == FAIL)
+ if (eval_expr_typval(expr, FALSE, NULL, 0, NULL, &rettv) == FAIL)
{
*error = TRUE;
return FALSE;