1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Fix callable without args not handled correctly

This commit is contained in:
kkmuffme 2023-12-18 12:48:13 +01:00
parent b38530ed0d
commit f8a53ebc5d
2 changed files with 14 additions and 1 deletions

View File

@ -288,7 +288,8 @@ final class HighOrderFunctionArgHandler
}
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;
}

View File

@ -2352,6 +2352,18 @@ class FunctionCallTest extends TestCase
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 {}