From d1d4682f9a2c216ded20dd2431a452c87ebb65a1 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 30 Oct 2025 18:25:44 +0300 Subject: [PATCH 1/4] add new info in logtext, change tests --- compiler/pipes/check-func-calls-and-vararg.cpp | 5 +++-- tests/phpt/ffi/typing/070_callback_params_error.php | 2 +- tests/phpt/ffi/typing/071_callback_params_error.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/pipes/check-func-calls-and-vararg.cpp b/compiler/pipes/check-func-calls-and-vararg.cpp index 9ac0736151..5285a71b6a 100644 --- a/compiler/pipes/check-func-calls-and-vararg.cpp +++ b/compiler/pipes/check-func-calls-and-vararg.cpp @@ -281,10 +281,11 @@ VertexPtr CheckFuncCallsAndVarargPass::on_func_call(VertexAdaptor 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(); int delta_this = f_callback->has_implicit_this_arg() ? 1 : 0; + auto expected_callback_signature = func_param->type_hint->try_as()->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..0596c110f5 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 Date: Thu, 30 Oct 2025 19:00:19 +0300 Subject: [PATCH 2/4] minifix --- compiler/pipes/check-func-calls-and-vararg.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/pipes/check-func-calls-and-vararg.cpp b/compiler/pipes/check-func-calls-and-vararg.cpp index 5285a71b6a..d9fadb3076 100644 --- a/compiler/pipes/check-func-calls-and-vararg.cpp +++ b/compiler/pipes/check-func-calls-and-vararg.cpp @@ -279,9 +279,10 @@ 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 = func_param->type_hint->try_as()->as_human_readable(); + auto expected_callback_signature = typed_callable->as_human_readable(); 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)); kphp_error(f_callback->get_params().size() >= call_n_params, From 128daa5142e2d08baf6471a43a5013d24e72d644 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Fri, 31 Oct 2025 19:45:57 +0300 Subject: [PATCH 3/4] add escapes --- tests/phpt/ffi/typing/070_callback_params_error.php | 2 +- tests/phpt/ffi/typing/071_callback_params_error.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpt/ffi/typing/070_callback_params_error.php b/tests/phpt/ffi/typing/070_callback_params_error.php index 0596c110f5..3ea3e59d95 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 many arguments for callback (callable(): void), expected 0, have 1 +Too many arguments for callback \(callable\(\): void\), expected 0, have 1 Date: Fri, 31 Oct 2025 19:47:07 +0300 Subject: [PATCH 4/4] minifix tests --- tests/phpt/ffi/typing/070_callback_params_error.php | 2 +- tests/phpt/ffi/typing/071_callback_params_error.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpt/ffi/typing/070_callback_params_error.php b/tests/phpt/ffi/typing/070_callback_params_error.php index 3ea3e59d95..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 many arguments for callback \(callable\(\): void\), expected 0, have 1 +/Too many arguments for callback \(callable\(\): void\), expected 0, have 1/