Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/pipes/check-func-calls-and-vararg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,14 @@ VertexPtr CheckFuncCallsAndVarargPass::on_func_call(VertexAdaptor<op_func_call>

if (f->is_extern() && func_param->type_hint && call_arg->type() == op_callback_of_builtin) {
if (FunctionPtr f_callback = call_arg.as<op_callback_of_builtin>()->func_id) {
int call_n_params = func_param->type_hint->try_as<TypeHintCallable>()->arg_types.size() + call_arg.as<op_callback_of_builtin>()->args().size();
const auto *typed_callable = func_param->type_hint->try_as<TypeHintCallable>();
int call_n_params = typed_callable->arg_types.size() + call_arg.as<op_callback_of_builtin>()->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<op_func_param>()->var()->ref_flag, "You can't pass callbacks with &references to built-in functions");
Expand Down
2 changes: 1 addition & 1 deletion tests/phpt/ffi/typing/070_callback_params_error.php
Original file line number Diff line number Diff line change
@@ -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/
<?php

function test() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpt/ffi/typing/071_callback_params_error.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@kphp_should_fail k2_skip
/Too many arguments in callback, expected 0, have 1/
/Too few arguments for callback \(callable\(int\): void\), expected 1, have 0/
<?php

function test() {
Expand Down
Loading