Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImplementedReturnTypeMismatch since version 3.4.6 when using Doctrine #1935

Closed
leroy0211 opened this issue Jul 11, 2019 · 1 comment
Closed
Labels

Comments

@leroy0211
Copy link

leroy0211 commented Jul 11, 2019

Since version 3.4.6 psalm throws an error ImplementedReturnTypeMismatch when using Doctrine. The error occurs on the find method of any Doctrine Repository.

The exact error is:
For privacy reasons the Repository is renamed to Foo.

ERROR: ImplementedReturnTypeMismatch - src/Repository/FooRepository.php:9:12 - The return type 'null|T as mixed' for Doctrine\Common\Persistence\ObjectRepository::find is different to the implemented return type for Doctrine\ORM\EntityRepository::find 'null|App\Entity\Foo'

I've validated if it's happening since this version by fixing the version to 3.4.5 and this error doesn't occur. When going to version 3.4.6 or any version higher, the error occurs.

The repository is just a simple repository generated from the maker-bundle command. But for any reference, here it is:

<?php

namespace App\Repository;

use App\Entity\Foo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method Foo|null find($id, $lockMode = null, $lockVersion = null)
 * @method Foo|null findOneBy(array $criteria, array $orderBy = null)
 * @method Foo[]    findAll()
 * @method Foo[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class FooRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Foo::class);
    }
}

The error occurs on the line:

 * @method Foo|null find($id, $lockMode = null, $lockVersion = null)
@muglug muglug added the bug label Jul 11, 2019
muglug added a commit that referenced this issue Jul 11, 2019
@muglug
Copy link
Collaborator

muglug commented Jul 11, 2019

Reproduced in a test here: 7d05568#diff-463cd1d277819cf78d66dadc84404891R930

cc @weirdan, as it involves your plugin (but you did nothing wrong). You may also want to stub out Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository with something like

/**
 * @template T
 * @template-extends EntityRepository<T>
 */
class ServiceEntityRepository extends EntityRepository {
}

to allow people to use @template-extends<Foo> in their repo files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants