1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix crash when using phantom methods as first-class callable

Fixes vimeo/psalm#8377
This commit is contained in:
Bruce Weirdan 2022-12-02 23:28:22 -04:00
parent 4defa177c8
commit 7364988934
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 30 additions and 11 deletions

View File

@ -685,18 +685,22 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer
}
}
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->getArgs(),
null,
null,
true,
$context
) === false) {
return;
}
if ($stmt->isFirstClassCallable()) {
$result->return_type = Type::getClosure();
} else {
if (ArgumentsAnalyzer::analyze(
$statements_analyzer,
$stmt->getArgs(),
null,
null,
true,
$context
) === false) {
return;
}
$result->return_type = Type::getMixed();
$result->return_type = Type::getMixed();
}
return;
default:

View File

@ -872,6 +872,21 @@ class ClosureTest extends TestCase
'ignored_issues' => [],
'php_version' => '8.1',
],
'FirstClassCallable:Method:Asserted' => [
'code' => '<?php
$r = false;
/** @var object $o */;
/** @var string $m */;
if (method_exists($o, $m)) {
$r = $o->$m(...);
}
',
'assertions' => [
'$r===' => 'Closure|false',
],
'ignored_issues' => [],
'php_version' => '8.1',
],
'arrowFunctionReturnsNeverImplictly' => [
'code' => '<?php
$bar = ["foo", "bar"];