1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix erroneous error about no parent when analysing trait call

This commit is contained in:
Matthew Brown 2018-01-09 09:22:23 -05:00
parent 93306710b6
commit 3f3c1380ee
2 changed files with 20 additions and 2 deletions

View File

@ -1278,9 +1278,11 @@ class CallChecker
&& in_array(strtolower($stmt->class->parts[0]), ['self', 'static', 'parent'], true)
) {
if ($stmt->class->parts[0] === 'parent') {
$fq_class_name = $statements_checker->getParentFQCLN();
$child_fq_class_name = $context->self;
if ($fq_class_name === null) {
$class_storage = $project_checker->classlike_storage_provider->get($child_fq_class_name);
if (!$class_storage->parent_classes) {
if (IssueBuffer::accepts(
new ParentNotFound(
'Cannot call method on parent as this class does not extend another',
@ -1294,6 +1296,8 @@ class CallChecker
return;
}
$fq_class_name = $class_storage->parent_classes[0];
$class_storage = $project_checker->classlike_storage_provider->get($fq_class_name);
if (is_string($stmt->name) && $class_storage->user_defined) {

View File

@ -352,6 +352,20 @@ class TraitTest extends TestCase
use T;
}',
],
'parentRefInTraitShouldNotFail' => [
'<?php
trait T {
public function foo() : void {
parent::foo();
}
}
class A {
public function foo() : void {}
}
class B extends A {
use T;
}',
],
];
}