diff --git a/src/Psalm/Internal/Type/Comparator/ObjectComparator.php b/src/Psalm/Internal/Type/Comparator/ObjectComparator.php index a0ae71166..5b2ea66ea 100644 --- a/src/Psalm/Internal/Type/Comparator/ObjectComparator.php +++ b/src/Psalm/Internal/Type/Comparator/ObjectComparator.php @@ -124,7 +124,7 @@ class ObjectComparator ); } - foreach ($intersection_input_types as $intersection_input_type) { + foreach ($intersection_input_types as $intersection_input_key => $intersection_input_type) { $input_was_static = false; if ($intersection_input_type instanceof TIterable) { @@ -239,7 +239,10 @@ class ObjectComparator $input_type_is_interface = $codebase->interfaceExists($intersection_input_type_lower); $container_type_is_interface = $codebase->interfaceExists($intersection_container_type_lower); - if ($allow_interface_equality && $container_type_is_interface) { + if ($allow_interface_equality + && $container_type_is_interface + && ($input_type_is_interface || !isset($intersection_container_types[$intersection_input_key])) + ) { continue 2; } diff --git a/tests/InterfaceTest.php b/tests/InterfaceTest.php index b5b946faa..1c96e7c1e 100644 --- a/tests/InterfaceTest.php +++ b/tests/InterfaceTest.php @@ -686,6 +686,21 @@ class InterfaceTest extends TestCase $f->m()->m(); }' ], + 'dontModifyAfterUnnecessaryAssertion' => [ + '