Skip to content

Commit

Permalink
Merge pull request #8435 from VincentLanglet/arrayReduce
Browse files Browse the repository at this point in the history
Add support for callable in array_reduce
  • Loading branch information
AndrolGenhald committed Aug 24, 2022
2 parents 034a796 + 6bc714c commit 88d3382
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -100,7 +100,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev

$initial_type = $reduce_return_type;

if ($closure_types = $function_call_arg_type->getClosureTypes()) {
if ($closure_types = $function_call_arg_type->getClosureTypes() ?: $function_call_arg_type->getCallableTypes()) {
$closure_atomic_type = reset($closure_types);

$closure_return_type = $closure_atomic_type->return_type ?: Type::getMixed();
Expand Down
16 changes: 16 additions & 0 deletions tests/ClosureTest.php
Expand Up @@ -565,6 +565,22 @@ function maker(string $className) {
'$result' => 'array{stdClass}'
],
],
'CallableWithArrayReduce' => [
'<?php
/**
* @return callable(int, int): int
*/
function maker() {
return function(int $sum, int $e) {
return $sum + $e;
};
}
$maker = maker();
$result = array_reduce([1, 2, 3], $maker, 0);',
'assertions' => [
'$result' => 'int'
],
],
'FirstClassCallable:NamedFunction:is_int' => [
'<?php
$closure = is_int(...);
Expand Down

0 comments on commit 88d3382

Please sign in to comment.