From ad0c442f1fcc6fe9c433777ee3e5b9e6addc6d69 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Aug 2023 22:15:47 +0200 Subject: patch 9.0.1723: Fix regression in {func} argument of reduce() 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 Co-authored-by: zeertzjq --- src/eval.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/eval.c') 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; -- cgit v1.2.3