Skip to content

Commit

Permalink
Merge pull request #8926 from danog/fix_8925
Browse files Browse the repository at this point in the history
Skip intersection of template types during inheritance check
  • Loading branch information
orklah committed Dec 18, 2022
2 parents da001c4 + 70d1a5a commit 8223332
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Psalm/Internal/Codebase/Methods.php
Expand Up @@ -768,8 +768,10 @@ public function getMethodReturnType(
$candidate_type
);

if ((!$old_contained_by_new && !$new_contained_by_old)
|| ($old_contained_by_new && $new_contained_by_old)
if (((!$old_contained_by_new && !$new_contained_by_old)
|| ($old_contained_by_new && $new_contained_by_old))
&& !$candidate_type->hasTemplate()
&& !$overridden_storage->return_type->hasTemplate()
) {
$attempted_intersection = null;
if ($old_contained_by_new) { //implicitly $new_contained_by_old as well
Expand Down
43 changes: 43 additions & 0 deletions tests/Template/ClassTemplateTest.php
Expand Up @@ -16,6 +16,49 @@ class ClassTemplateTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'templateIntersection' => [
'code' => '<?php
interface EntityInterface
{
public function getId(): string;
}
/**
* @phpstan-template T of EntityInterface
*/
interface RepositoryInterface
{
/**
* @return T|null
*/
public function byId(string $id);
}
final class Foo implements EntityInterface
{
public function getId(): string
{
return "42";
}
}
/**
* @phpstan-implements RepositoryInterface<Foo>
*/
final class FooRepository implements RepositoryInterface
{
/**
* @var Foo[]
*/
public array $elements = [];
public function byId(string $id): ?Foo
{
return $this->elements[$id] ?? null;
}
}
'
],
'cachingIterator' => [
'code' => '<?php
Expand Down

0 comments on commit 8223332

Please sign in to comment.