1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix trait method evaluation order

This commit is contained in:
Matthew Brown 2017-12-29 11:26:28 -05:00
parent c38cf9b672
commit 0b58ee425d
4 changed files with 38 additions and 14 deletions

View File

@ -115,6 +115,9 @@ trait CanAlias
return $this->aliased_classes_flipped;
}
/**
* @return Aliases
*/
public function getAliases()
{
return new Aliases(

View File

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

View File

@ -122,7 +122,7 @@ trait GenericTrait
}
/**
* @param array<string, string|Type\Union> $template_types
* @param array<string, string|Union> $template_types
*
* @return void
*/

View File

@ -162,6 +162,27 @@ class UnusedCodeTest extends TestCase
$m->foo("value");
$m->modifyFoo("value2");',
],
'usedTraitMethod' => [
'<?php
class A {
public function foo() : void {
echo "parent method";
}
}
trait T {
public function foo() : void {
echo "trait method";
}
}
class B extends A {
use T;
}
(new A)->foo();
(new B)->foo();',
],
];
}