diff --git a/src/Psalm/Checker/CanAlias.php b/src/Psalm/Checker/CanAlias.php index 2c08b71c8..2dff24af0 100644 --- a/src/Psalm/Checker/CanAlias.php +++ b/src/Psalm/Checker/CanAlias.php @@ -115,6 +115,9 @@ trait CanAlias return $this->aliased_classes_flipped; } + /** + * @return Aliases + */ public function getAliases() { return new Aliases( diff --git a/src/Psalm/Checker/ProjectChecker.php b/src/Psalm/Checker/ProjectChecker.php index a01475aa9..acc0bbfd4 100644 --- a/src/Psalm/Checker/ProjectChecker.php +++ b/src/Psalm/Checker/ProjectChecker.php @@ -566,6 +566,19 @@ class ProjectChecker $storage_provider = $this->classlike_storage_provider; + foreach ($storage->used_traits as $used_trait_lc => $used_trait) { + try { + $trait_storage = $storage_provider->get($used_trait_lc); + } catch (\InvalidArgumentException $e) { + continue; + } + + $this->populateClassLikeStorage($trait_storage, $dependent_classlikes); + + $this->inheritMethodsFromParent($storage, $trait_storage); + $this->inheritPropertiesFromParent($storage, $trait_storage); + } + $dependent_classlikes[strtolower($storage->name)] = true; if (isset($storage->parent_classes[0])) { @@ -657,19 +670,6 @@ class ProjectChecker } } - foreach ($storage->used_traits as $used_trait_lc => $used_trait) { - try { - $trait_storage = $storage_provider->get($used_trait_lc); - } catch (\InvalidArgumentException $e) { - continue; - } - - $this->populateClassLikeStorage($trait_storage, $dependent_classlikes); - - $this->inheritMethodsFromParent($storage, $trait_storage); - $this->inheritPropertiesFromParent($storage, $trait_storage); - } - if ($storage->location) { $file_path = $storage->location->file_path; diff --git a/src/Psalm/Type/Atomic/GenericTrait.php b/src/Psalm/Type/Atomic/GenericTrait.php index 81b0675d2..0bd9e1ec0 100644 --- a/src/Psalm/Type/Atomic/GenericTrait.php +++ b/src/Psalm/Type/Atomic/GenericTrait.php @@ -122,7 +122,7 @@ trait GenericTrait } /** - * @param array $template_types + * @param array $template_types * * @return void */ diff --git a/tests/UnusedCodeTest.php b/tests/UnusedCodeTest.php index 679a0b7d9..41e936f57 100644 --- a/tests/UnusedCodeTest.php +++ b/tests/UnusedCodeTest.php @@ -162,6 +162,27 @@ class UnusedCodeTest extends TestCase $m->foo("value"); $m->modifyFoo("value2");', ], + 'usedTraitMethod' => [ + 'foo(); + (new B)->foo();', + ], ]; }