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

LessSpecificReturnType on EntityManagerInterface::find #93

Open
boesing opened this issue Jul 15, 2021 · 0 comments
Open

LessSpecificReturnType on EntityManagerInterface::find #93

boesing opened this issue Jul 15, 2021 · 0 comments

Comments

@boesing
Copy link

boesing commented Jul 15, 2021

Hey there,

somehow, psalm asserts that the return type of find is not nullable.
The generic is properly detected tho.

Code

use Doctrine\ORM\EntityManagerInterface;

final class Foo
{
    /**
     * @var EntityManagerInterface
     */
    private $entityManager;
    /**
     * @psalm-param positive-int $id
     */
    private function status(int $leadId): ?Entity
    {
        return $this->entityManager->find(Entity::class, $leadId);
    }
}

Psalm output

ERROR: LessSpecificReturnType - The inferred return type 'Entity' for Foo::status is more specific than the declared return type 'Entity|null' (see https://psalm.dev/088)
    private function status(int $leadId): ?Entity

Versions

Package Version
vimeo/psalm  4.7.0
weirdan/doctrine-psalm-plugin 1.0.0
doctrine/orm  2.7.5

I've already tried to replace ?T with T|null locally (within the stubfile, and cleared cache afterwards) but that did not work as expected.

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

No branches or pull requests

1 participant