From 0f30d232513ea72b799482c9d25e057da5ad1eb1 Mon Sep 17 00:00:00 2001 From: KorsarOfficial Date: Thu, 19 Mar 2026 01:01:48 +0400 Subject: [PATCH] fix: swap 'Too many'/'Too few' messages and correct expected/have in callback arg errors (#42) The two error messages for callback argument count mismatches in check-func-calls-and-vararg.cpp had their labels swapped and their printf arguments in the wrong order: - The condition `call_n_params >= get_min_argn()` is false when there are TOO FEW arguments, but the message said "Too many arguments for callback". - The condition `get_params().size() >= call_n_params` is false when there are TOO MANY arguments, but the message said "Too few arguments for callback". - In both cases the "expected" and "have" values were transposed. Fix: swap the two message strings and swap the fmt_format arguments to match the corrected messages and mirror the non-callback pattern on lines 271-274. --- compiler/pipes/check-func-calls-and-vararg.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/pipes/check-func-calls-and-vararg.cpp b/compiler/pipes/check-func-calls-and-vararg.cpp index d9fadb3076..a887906378 100644 --- a/compiler/pipes/check-func-calls-and-vararg.cpp +++ b/compiler/pipes/check-func-calls-and-vararg.cpp @@ -283,10 +283,13 @@ VertexPtr CheckFuncCallsAndVarargPass::on_func_call(VertexAdaptor int call_n_params = typed_callable->arg_types.size() + call_arg.as()->args().size(); int delta_this = f_callback->has_implicit_this_arg() ? 1 : 0; auto expected_callback_signature = typed_callable->as_human_readable(); + // Note: "Too few" fires when call_n_params < get_min_argn() (condition is false), + // "Too many" fires when call_n_params > get_params().size() (condition is false). + // expected/have mirror the non-callback pattern on lines 271-274. kphp_error(call_n_params >= f_callback->get_min_argn(), - fmt_format("Too many arguments for callback ({}), expected {}, have {}", expected_callback_signature, call_n_params - delta_this, f_callback->get_min_argn() - delta_this)); + fmt_format("Too few arguments for callback ({}), expected {}, have {}", expected_callback_signature, f_callback->get_min_argn() - delta_this, call_n_params - delta_this)); kphp_error(f_callback->get_params().size() >= call_n_params, - fmt_format("Too few arguments for callback ({}), expected {}, have {}", expected_callback_signature, call_n_params - delta_this, f_callback->get_params().size() - delta_this)); + fmt_format("Too many arguments for callback ({}), expected {}, have {}", expected_callback_signature, f_callback->get_params().size() - delta_this, call_n_params - delta_this)); for (auto p : f_callback->get_params()) { kphp_error(!p.as()->var()->ref_flag, "You can't pass callbacks with &references to built-in functions");