From bccda92f31ae26cbcb660fc3b57f08016812ece2 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 18 Dec 2022 17:11:53 +0100 Subject: [PATCH 1/2] Skip intersection of template types during inheritance check --- src/Psalm/Internal/Codebase/Methods.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index 940edc9c472..459f8496e3e 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -768,8 +768,10 @@ public function getMethodReturnType( $candidate_type ); - if ((!$old_contained_by_new && !$new_contained_by_old) - || ($old_contained_by_new && $new_contained_by_old) + if (((!$old_contained_by_new && !$new_contained_by_old) + || ($old_contained_by_new && $new_contained_by_old)) + && !$candidate_type->hasTemplate() + && !$overridden_storage->return_type->hasTemplate() ) { $attempted_intersection = null; if ($old_contained_by_new) { //implicitly $new_contained_by_old as well From 70d1a5a3c527ad8c1a007198f3dde1044446323b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 18 Dec 2022 18:14:43 +0100 Subject: [PATCH 2/2] Add test --- tests/Template/ClassTemplateTest.php | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index f447f8d8c00..6c40d7a031b 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -16,6 +16,49 @@ class ClassTemplateTest extends TestCase public function providerValidCodeParse(): iterable { return [ + 'templateIntersection' => [ + 'code' => ' + */ + final class FooRepository implements RepositoryInterface + { + /** + * @var Foo[] + */ + public array $elements = []; + + public function byId(string $id): ?Foo + { + return $this->elements[$id] ?? null; + } + } + ' + ], 'cachingIterator' => [ 'code' => '