Skip to content
Permalink
Browse files

Fix #1686 - intersect object and named class properly

  • Loading branch information...
muglug committed May 26, 2019
1 parent 0525991 commit 97f4cdb7f51f671e7a09c3a5e2a002e405b021a4
Showing with 29 additions and 1 deletion.
  1. +6 −1 src/Psalm/Type.php
  2. +23 −0 tests/InterfaceTest.php
@@ -1340,7 +1340,7 @@ public static function intersectUnionTypes(
} 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 @@ public static function intersectUnionTypes(
}
}
}
if ($type_1_atomic instanceof TObject && $type_2_atomic instanceof TNamedObject) {
$combined_type->removeType($t1_key);
$combined_type->addType(clone $type_2_atomic);
}
}
}
}
@@ -581,6 +581,29 @@ function iBarFirst($i) : string {
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();
}',
],
];
}

0 comments on commit 97f4cdb

Please sign in to comment.
You can’t perform that action at this time.