1
0
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:
Bruce Weirdan 2023-08-28 01:58:02 +02:00
parent 77436b1339
commit b3150d451a
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 23 additions and 0 deletions

View File

@ -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;

View File

@ -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'],
],
];
}
}