1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

feature: treat class-string<callable> as callable-object

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
This commit is contained in:
Maximilian Bösing 2023-04-04 17:28:49 +02:00
parent b18fb9691b
commit 6c58d98d67
No known key found for this signature in database
GPG Key ID: 9A8988C93CEC81A3
2 changed files with 27 additions and 0 deletions

View File

@ -718,6 +718,10 @@ class TypeParser
continue; continue;
} }
if ($type instanceof TCallable) {
$type = new TCallableObject($from_docblock, $type);
}
if ($type instanceof TCallableObject) { if ($type instanceof TCallableObject) {
$types[] = new TUnknownClassString($type, false, $from_docblock); $types[] = new TUnknownClassString($type, false, $from_docblock);
continue; continue;

View File

@ -92,6 +92,29 @@ final class IntersectionTypeTest extends TestCase
'assertions' => [], 'assertions' => [],
'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'],
], ],
'classStringOfCallableWillBeTreatedAsCallableObject' => [
'code' => '<?php
/**
* @param class-string<callable():int> $className
*/
function takesCallableObject(string $className): int {
$object = new $className();
return $object();
}
class Foo
{
public function __invoke(): int
{
return 0;
}
}
takesCallableObject(Foo::class);
',
'assertions' => [],
'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'],
],
]; ];
} }