Skip to content

Commit

Permalink
Fix callable without args not handled correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Dec 18, 2023
1 parent b38530e commit f8a53eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ private static function isSupported(FunctionLikeParameter $container_param): boo
}

foreach ($container_param->type->getAtomicTypes() as $a) {
if (($a instanceof TClosure || $a instanceof TCallable) && !$a->params) {
// must check null explicitly, since no params (empty array) would not be handled correctly otherwise
if (($a instanceof TClosure || $a instanceof TCallable) && $a->params === null) {
return false;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,18 @@ function fooFoo(int $a): void {}
fooFoo("string");',
'error_message' => 'InvalidScalarArgument',
],
'invalidArgumentCallableWithoutArgsUnion' => [
'code' => '<?php
function foo(int $a): void {}
/**
* @param callable()|float $callable
* @return void
*/
function acme($callable) {}
acme("foo");',
'error_message' => 'InvalidArgument',
],
'invalidArgumentWithDeclareStrictTypes' => [
'code' => '<?php declare(strict_types=1);
function fooFoo(int $a): void {}
Expand Down

0 comments on commit f8a53eb

Please sign in to comment.