mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix crash on property access to undefined property on a class with a missing dependncy
This commit is contained in:
parent
77436b1339
commit
b3150d451a
@ -501,6 +501,10 @@ final class ClassLikeStorage implements HasAttributesInterface
|
||||
}
|
||||
|
||||
foreach ($this->parent_classes as $parent_class) {
|
||||
// skip missing dependencies
|
||||
if (!$codebase->classlike_storage_provider->has($parent_class)) {
|
||||
continue;
|
||||
}
|
||||
$parent_class_storage = $codebase->classlike_storage_provider->get($parent_class);
|
||||
if ($parent_class_storage->hasAttribute($fq_class_name)) {
|
||||
return true;
|
||||
|
@ -5,11 +5,13 @@ declare(strict_types=1);
|
||||
namespace Psalm\Tests\Internal\Analyzer\Statements\Expression\Fetch;
|
||||
|
||||
use Psalm\Tests\TestCase;
|
||||
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
|
||||
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
|
||||
|
||||
final class AtomicPropertyFetchAnalyzerTest extends TestCase
|
||||
{
|
||||
use ValidCodeAnalysisTestTrait;
|
||||
use InvalidCodeAnalysisTestTrait;
|
||||
|
||||
public function providerValidCodeParse(): iterable
|
||||
{
|
||||
@ -72,4 +74,21 @@ final class AtomicPropertyFetchAnalyzerTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function providerInvalidCodeParse(): iterable
|
||||
{
|
||||
return [
|
||||
'undefinedPropertyAccessOnMissingDependency' => [
|
||||
'code' => <<<'PHP'
|
||||
<?php
|
||||
class A extends Missing {}
|
||||
function make(): A { return new A; }
|
||||
|
||||
make()->prop;
|
||||
PHP,
|
||||
'error_message' => 'UndefinedPropertyFetch',
|
||||
'ignored_issues' => ['MissingDependency'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user