Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using phantom methods as first-class callable #8814

Merged
merged 1 commit into from Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -685,18 +685,22 @@ private static function handleInvalidClass(
}
}

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:
Expand Down
15 changes: 15 additions & 0 deletions tests/ClosureTest.php
Expand Up @@ -872,6 +872,21 @@ private function handler(): void {
'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"];
Expand Down