From 1f295e4597703e05eb02795822d5f0b7205a7cd6 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Sun, 13 Dec 2020 16:57:51 -0500 Subject: [PATCH] Fix psl inheritance stuff cc @azjezz --- src/Psalm/Internal/Codebase/Populator.php | 17 ++++++++- tests/Template/ClassTemplateExtendsTest.php | 42 +++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Populator.php b/src/Psalm/Internal/Codebase/Populator.php index 84a040fcb..d047eb215 100644 --- a/src/Psalm/Internal/Codebase/Populator.php +++ b/src/Psalm/Internal/Codebase/Populator.php @@ -673,8 +673,6 @@ class Populator ); } - $parent_interface_storage->dependent_classlikes[strtolower($storage->name)] = true; - $parent_interfaces = array_merge($parent_interfaces, $parent_interface_storage->parent_interfaces); $this->inheritMethodsFromParent($storage, $parent_interface_storage); @@ -683,6 +681,21 @@ class Populator } $storage->parent_interfaces = array_merge($parent_interfaces, $storage->parent_interfaces); + + foreach ($storage->parent_interfaces as $parent_interface_lc => $_) { + try { + $parent_interface_lc = strtolower( + $this->classlikes->getUnAliasedName( + $parent_interface_lc + ) + ); + $parent_interface_storage = $storage_provider->get($parent_interface_lc); + } catch (\InvalidArgumentException $e) { + continue; + } + + $parent_interface_storage->dependent_classlikes[strtolower($storage->name)] = true; + } } private function populateDataFromImplementedInterfaces( diff --git a/tests/Template/ClassTemplateExtendsTest.php b/tests/Template/ClassTemplateExtendsTest.php index dbb0c7ad8..41ddbf88e 100644 --- a/tests/Template/ClassTemplateExtendsTest.php +++ b/tests/Template/ClassTemplateExtendsTest.php @@ -4240,6 +4240,48 @@ class ClassTemplateExtendsTest extends TestCase [], '7.4' ], + 'inheritInterfacesManyTimes' => [ + ' + */ + interface C1 extends \IteratorAggregate + { + } + + /** + * @template Tv + * + * @extends C1 + */ + interface C2 extends C1 + { + } + + /** + * @template Tv + * + * @extends C2 + */ + interface C3 extends C2 + { + } + + /** + * @template Tv + * + * @extends C3 + */ + interface C4 extends C3 + { + /** + * @psalm-return Traversable + */ + function getIterator(): Traversable; + }' + ], ]; }