1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #1686 - intersect object and named class properly

This commit is contained in:
Matthew Brown 2019-05-26 13:11:43 -04:00
parent 052599192a
commit 97f4cdb7f5
2 changed files with 29 additions and 1 deletions

View File

@ -1340,7 +1340,7 @@ abstract class Type
} else {
$combined_type = clone $type_1;
foreach ($combined_type->getTypes() as $type_1_atomic) {
foreach ($combined_type->getTypes() as $t1_key => $type_1_atomic) {
foreach ($type_2->getTypes() as $type_2_atomic) {
if (($type_1_atomic instanceof TIterable
|| $type_1_atomic instanceof TNamedObject
@ -1367,6 +1367,11 @@ abstract class Type
}
}
}
if ($type_1_atomic instanceof TObject && $type_2_atomic instanceof TNamedObject) {
$combined_type->removeType($t1_key);
$combined_type->addType(clone $type_2_atomic);
}
}
}
}

View File

@ -581,6 +581,29 @@ class InterfaceTest extends TestCase
return $i->foo();
}',
],
'intersectionObjectTypes' => [
'<?php
class C {}
interface IFoo {
function foo() : object;
}
interface IBar {
function foo() : C;
}
/** @param IFoo&IBar $i */
function iFooFirst($i) : C {
return $i->foo();
}
/** @param IBar&IFoo $i */
function iBarFirst($i) : C {
return $i->foo();
}',
],
];
}