Skip to content

Commit

Permalink
Merge pull request #8817 from weirdan/fix-7863
Browse files Browse the repository at this point in the history
Fixes #7863
  • Loading branch information
weirdan committed Dec 3, 2022
2 parents e64913c + a157743 commit 14d48a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Psalm/Internal/Analyzer/TraitAnalyzer.php
Expand Up @@ -67,7 +67,14 @@ public function getAliasedClassesFlippedReplaceable(): array
public static function analyze(StatementsAnalyzer $statements_analyzer, Trait_ $stmt, Context $context): void
{
assert($stmt->name !== null);
$storage = $statements_analyzer->getCodebase()->classlike_storage_provider->get($stmt->name->name);
$codebase = $statements_analyzer->getCodebase();

if (!$codebase->classlike_storage_provider->has($stmt->name->name)) {
return;
}

$storage = $codebase->classlike_storage_provider->get($stmt->name->name);

AttributesAnalyzer::analyze(
$statements_analyzer,
$context,
Expand Down
8 changes: 8 additions & 0 deletions tests/TraitTest.php
Expand Up @@ -996,6 +996,14 @@ final class A {
#[Attribute]
trait Foo {}',
],
'noCrashOnConditionalTrait' => [
'code' => '<?php
namespace NS;
if (rand(0, 1)) {
trait T {}
}
'
],
];
}

Expand Down

0 comments on commit 14d48a0

Please sign in to comment.