mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +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:
parent
b18fb9691b
commit
6c58d98d67
@ -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;
|
||||||
|
@ -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'],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user