From 4e8fb9c37f182f9f556f2d2d95d7e1d824490175 Mon Sep 17 00:00:00 2001 From: Thomas Mauro Vargiu Date: Mon, 16 Nov 2020 02:29:49 +0100 Subject: [PATCH] Fix #4549 Better intersection between parent types (#4560) --- src/Psalm/Internal/Codebase/Methods.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index f7456dfae..df4ead7d6 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -779,11 +779,19 @@ class Methods if ((!$old_contained_by_new && !$new_contained_by_old) || ($old_contained_by_new && $new_contained_by_old) ) { - $attempted_intersection = Type::intersectUnionTypes( - $overridden_storage->return_type, - $candidate_type, - $source_analyzer->getCodebase() - ); + if ($old_contained_by_new && $new_contained_by_old) { + $attempted_intersection = Type::intersectUnionTypes( + $candidate_type, + $overridden_storage->return_type, + $source_analyzer->getCodebase() + ); + } else { + $attempted_intersection = Type::intersectUnionTypes( + $overridden_storage->return_type, + $candidate_type, + $source_analyzer->getCodebase() + ); + } if ($attempted_intersection) { $self_class = $overridden_method_id->fq_class_name;