mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix undefined parent not reported in callable
Fix https://github.com/vimeo/psalm/issues/10836
This commit is contained in:
parent
4ea41cb69a
commit
ff168a9c7a
@ -38,6 +38,7 @@ use Psalm\Issue\MixedArgumentTypeCoercion;
|
||||
use Psalm\Issue\NamedArgumentNotAllowed;
|
||||
use Psalm\Issue\NoValue;
|
||||
use Psalm\Issue\NullArgument;
|
||||
use Psalm\Issue\ParentNotFound;
|
||||
use Psalm\Issue\PossiblyFalseArgument;
|
||||
use Psalm\Issue\PossiblyInvalidArgument;
|
||||
use Psalm\Issue\PossiblyNullArgument;
|
||||
@ -1297,6 +1298,16 @@ final class ArgumentAnalyzer
|
||||
|
||||
if ($callable_fq_class_name === 'parent') {
|
||||
$container_class = $statements_analyzer->getParentFQCLN();
|
||||
if ($container_class === null) {
|
||||
IssueBuffer::accepts(
|
||||
new ParentNotFound(
|
||||
'Cannot call method on parent'
|
||||
. ' as this class does not extend another',
|
||||
$arg_location,
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$container_class) {
|
||||
|
@ -2518,6 +2518,40 @@ class CallableTest extends TestCase
|
||||
'ignored_issues' => [],
|
||||
'php_version' => '8.0',
|
||||
],
|
||||
'parentCallableArrayWithoutParent' => [
|
||||
'code' => '<?php
|
||||
class A {
|
||||
public function __construct() {
|
||||
$this->run(["parent", "hello"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $callable
|
||||
* @return void
|
||||
*/
|
||||
public function run($callable) {
|
||||
call_user_func($callable);
|
||||
}
|
||||
}',
|
||||
'error_message' => 'ParentNotFound',
|
||||
],
|
||||
'parentCallableWithoutParent' => [
|
||||
'code' => '<?php
|
||||
class A {
|
||||
public function __construct() {
|
||||
$this->run("parent::hello");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $callable
|
||||
* @return void
|
||||
*/
|
||||
public function run($callable) {
|
||||
call_user_func($callable);
|
||||
}
|
||||
}',
|
||||
'error_message' => 'ParentNotFound',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user