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

PossiblyInvalidArgument false-positive for Collection methods #92

Open
fluffycondor opened this issue Jun 23, 2021 · 0 comments
Open

PossiblyInvalidArgument false-positive for Collection methods #92

fluffycondor opened this issue Jun 23, 2021 · 0 comments

Comments

@fluffycondor
Copy link
Contributor

fluffycondor commented Jun 23, 2021

vimeo/psalm 4.8.1
weirdan/doctrine-psalm-plugin 1.0.0

/** @param Collection<int, A>|Collection<int, B> */
public function deleteItemById(Collection $collection, int $id): void
{
    $matchedItems = $collection->filter(
        static function ($inCollectionItem) use ($id): bool {
            return $inCollectionItem->haveId($id);
        }
    );

    if (!$matchedItems->isEmpty()) {
        $collection->removeElement($matchedItems->first()); // yields PossiblyInvalidArgument
    }
}

psalm: PossiblyInvalidArgument: Argument 1 of Doctrine\Common\Collections\Collection::removeElement expects A, possibly different type A|B provided

It looks false-positive to me, it's impossible to call here Collection<int, A>::removeElement(B).

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