diff --git a/compiler/pipes/check-func-calls-and-vararg.cpp b/compiler/pipes/check-func-calls-and-vararg.cpp index 9ac0736151..d9fadb3076 100644 --- a/compiler/pipes/check-func-calls-and-vararg.cpp +++ b/compiler/pipes/check-func-calls-and-vararg.cpp @@ -279,12 +279,14 @@ VertexPtr CheckFuncCallsAndVarargPass::on_func_call(VertexAdaptor if (f->is_extern() && func_param->type_hint && call_arg->type() == op_callback_of_builtin) { if (FunctionPtr f_callback = call_arg.as()->func_id) { - int call_n_params = func_param->type_hint->try_as()->arg_types.size() + call_arg.as()->args().size(); + const auto *typed_callable = func_param->type_hint->try_as(); + 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(); kphp_error(call_n_params >= f_callback->get_min_argn(), - fmt_format("Too few arguments in callback, expected {}, have {}", f_callback->get_min_argn() - delta_this, call_n_params - delta_this)); + fmt_format("Too many arguments for callback ({}), expected {}, have {}", expected_callback_signature, call_n_params - delta_this, f_callback->get_min_argn() - delta_this)); kphp_error(f_callback->get_params().size() >= call_n_params, - fmt_format("Too many arguments in callback, expected {}, have {}", f_callback->get_params().size() - delta_this, call_n_params - delta_this)); + fmt_format("Too few arguments for callback ({}), expected {}, have {}", expected_callback_signature, call_n_params - delta_this, f_callback->get_params().size() - 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"); diff --git a/tests/phpt/ffi/typing/070_callback_params_error.php b/tests/phpt/ffi/typing/070_callback_params_error.php index bbab39ce5a..867e2d65fa 100644 --- a/tests/phpt/ffi/typing/070_callback_params_error.php +++ b/tests/phpt/ffi/typing/070_callback_params_error.php @@ -1,5 +1,5 @@ @kphp_should_fail k2_skip -/Too few arguments in callback, expected 1, have 0/ +/Too many arguments for callback \(callable\(\): void\), expected 0, have 1/