diff src/eval.c @ 32818:705d0e1329a5 v9.0.1723

patch 9.0.1723: Fix regression in {func} argument of reduce() Commit: https://github.com/vim/vim/commit/ad0c442f1fcc6fe9c433777ee3e5b9e6addc6d69 Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Aug 17 22:15:47 2023 +0200 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 <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
author Christian Brabandt <cb@256bit.org>
date Thu, 17 Aug 2023 22:30:02 +0200
parents 695b50472e85
children a39314fa9495
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -252,12 +252,14 @@ eval_expr_get_funccal(typval_T *expr, ty
 /*
  * 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 *e
     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;