mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Don’t modify object after unnecessary assertion
This commit is contained in:
parent
7adc25c421
commit
11f170acb4
@ -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;
|
||||
}
|
||||
|
||||
|
@ -686,6 +686,21 @@ class InterfaceTest extends TestCase
|
||||
$f->m()->m();
|
||||
}'
|
||||
],
|
||||
'dontModifyAfterUnnecessaryAssertion' => [
|
||||
'<?php
|
||||
class A {}
|
||||
interface I {}
|
||||
|
||||
/**
|
||||
* @param A&I $a
|
||||
* @return A&I
|
||||
*/
|
||||
function foo(I $a) {
|
||||
/** @psalm-suppress RedundantConditionGivenDocblockType */
|
||||
assert($a instanceof A);
|
||||
return $a;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user