comparison 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
comparison
equal deleted inserted replaced
32817:4fa5838c6952 32818:705d0e1329a5
250 } 250 }
251 251
252 /* 252 /*
253 * Evaluate an expression, which can be a function, partial or string. 253 * Evaluate an expression, which can be a function, partial or string.
254 * Pass arguments "argv[argc]". 254 * Pass arguments "argv[argc]".
255 * If "want_func" is TRUE treat a string as a function name, not an expression.
255 * "fc_arg" is from eval_expr_get_funccal() or NULL; 256 * "fc_arg" is from eval_expr_get_funccal() or NULL;
256 * Return the result in "rettv" and OK or FAIL. 257 * Return the result in "rettv" and OK or FAIL.
257 */ 258 */
258 int 259 int
259 eval_expr_typval( 260 eval_expr_typval(
260 typval_T *expr, 261 typval_T *expr,
262 int want_func,
261 typval_T *argv, 263 typval_T *argv,
262 int argc, 264 int argc,
263 funccall_T *fc_arg, 265 funccall_T *fc_arg,
264 typval_T *rettv) 266 typval_T *rettv)
265 { 267 {
266 char_u *s; 268 char_u *s;
267 char_u buf[NUMBUFLEN]; 269 char_u buf[NUMBUFLEN];
268 funcexe_T funcexe; 270 funcexe_T funcexe;
269 271
270 if (expr->v_type == VAR_FUNC) 272 if (expr->v_type == VAR_PARTIAL)
271 {
272 s = expr->vval.v_string;
273 if (s == NULL || *s == NUL)
274 return FAIL;
275 CLEAR_FIELD(funcexe);
276 funcexe.fe_evaluate = TRUE;
277 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
278 return FAIL;
279 }
280 else if (expr->v_type == VAR_PARTIAL)
281 { 273 {
282 partial_T *partial = expr->vval.v_partial; 274 partial_T *partial = expr->vval.v_partial;
283 275
284 if (partial == NULL) 276 if (partial == NULL)
285 return FAIL; 277 return FAIL;
316 } 308 }
317 else if (expr->v_type == VAR_INSTR) 309 else if (expr->v_type == VAR_INSTR)
318 { 310 {
319 return exe_typval_instr(expr, rettv); 311 return exe_typval_instr(expr, rettv);
320 } 312 }
313 else if (expr->v_type == VAR_FUNC || want_func)
314 {
315 s = expr->v_type == VAR_FUNC
316 ? expr->vval.v_string
317 : tv_get_string_buf_chk_strict(expr, buf, in_vim9script());
318 if (s == NULL || *s == NUL)
319 return FAIL;
320 CLEAR_FIELD(funcexe);
321 funcexe.fe_evaluate = TRUE;
322 if (call_func(s, -1, rettv, argc, argv, &funcexe) == FAIL)
323 return FAIL;
324 }
321 else 325 else
322 { 326 {
323 s = tv_get_string_buf_chk_strict(expr, buf, in_vim9script()); 327 s = tv_get_string_buf_chk_strict(expr, buf, in_vim9script());
324 if (s == NULL) 328 if (s == NULL)
325 return FAIL; 329 return FAIL;
344 eval_expr_to_bool(typval_T *expr, int *error) 348 eval_expr_to_bool(typval_T *expr, int *error)
345 { 349 {
346 typval_T rettv; 350 typval_T rettv;
347 int res; 351 int res;
348 352
349 if (eval_expr_typval(expr, NULL, 0, NULL, &rettv) == FAIL) 353 if (eval_expr_typval(expr, FALSE, NULL, 0, NULL, &rettv) == FAIL)
350 { 354 {
351 *error = TRUE; 355 *error = TRUE;
352 return FALSE; 356 return FALSE;
353 } 357 }
354 res = (tv_get_bool_chk(&rettv, error) != 0); 358 res = (tv_get_bool_chk(&rettv, error) != 0);