Skip to content

Commit

Permalink
Merge pull request #10159 from vimeo/fix-crash-on-property-access-wit…
Browse files Browse the repository at this point in the history
…h-missing-dependency
  • Loading branch information
weirdan committed Aug 28, 2023
2 parents 77436b1 + b3150d4 commit b29ea52
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Psalm/Storage/ClassLikeStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ public function hasAttributeIncludingParents(
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
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
{
Expand Down Expand Up @@ -72,4 +74,21 @@ class C extends B {}
],
];
}

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

0 comments on commit b29ea52

Please sign in to comment.