Skip to content

Commit

Permalink
Merge pull request #10838 from kkmuffme/undefined-parent-not-reported…
Browse files Browse the repository at this point in the history
…-in-callable
  • Loading branch information
weirdan committed Mar 20, 2024
2 parents f61c7e1 + ff168a9 commit e3d5526
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -1297,6 +1298,16 @@ private static function verifyExplicitParam(

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) {
Expand Down
34 changes: 34 additions & 0 deletions tests/CallableTest.php
Expand Up @@ -2533,6 +2533,40 @@ function f(callable $c): void {
'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',
],
];
}
}

0 comments on commit e3d5526

Please sign in to comment.