Skip to content
Permalink
Browse files

Fix #2490 - allow overriding renamed trait methods in subclass

  • Loading branch information
muglug committed Dec 20, 2019
1 parent 8c1638e commit 59aeb6b6c3f1ee5c0474da8b63af8818318138d7
Showing with 29 additions and 7 deletions.
  1. +4 −7 src/Psalm/Internal/Codebase/Populator.php
  2. +25 −0 tests/TraitTest.php
@@ -274,17 +274,14 @@ private function populateOverriddenMethods(
= $declaring_class_storages[$declaring_class]
= $this->classlike_storage_provider->get($declaring_class);

if (!isset($declaring_class_storage->overridden_method_ids[$method_name])) {
throw new \UnexpectedValueException('Declaring storage should have ids');
}

if ($candidate_overridden_ids === null) {
$candidate_overridden_ids = $declaring_class_storage->overridden_method_ids[$method_name]
+ [$declaring_method_id => $declaring_method_id];
$candidate_overridden_ids
= ($declaring_class_storage->overridden_method_ids[$method_name] ?? [])
+ [$declaring_method_id => $declaring_method_id];
} else {
$candidate_overridden_ids = \array_intersect_key(
$candidate_overridden_ids,
$declaring_class_storage->overridden_method_ids[$method_name]
($declaring_class_storage->overridden_method_ids[$method_name] ?? [])
+ [$declaring_method_id => $declaring_method_id]
);
}
@@ -895,6 +895,31 @@ class Application {
use Feature;
}',
],
'renameMethodNoCrash' => [
'<?php
trait HelloTrait {
protected function sayHello() : string {
return "Hello";
}
}
class Person {
use HelloTrait {
sayHello as orginalSayHello;
}
protected function sayHello() : string {
return $this->orginalSayHello();
}
}
class BrokenPerson extends Person {
protected function orginalSayHello() : string {
return "bad";
}
}',
],
];
}

0 comments on commit 59aeb6b

Please sign in to comment.
You can’t perform that action at this time.