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

False positive for InvalidArgument Error with \DateTimeImmutable #2948

Closed
jrushlow opened this issue Mar 9, 2020 · 5 comments
Closed

False positive for InvalidArgument Error with \DateTimeImmutable #2948

jrushlow opened this issue Mar 9, 2020 · 5 comments

Comments

@jrushlow
Copy link

jrushlow commented Mar 9, 2020

False Error by psalm when passing a \DateTimeImmutable::class to a method that expects a \DateTimeInterface::class. This appeared after composer update:

vimeo/psalm dev-master a2a5071 dev-master a0da735 A static analysis tool for finding errors in PHP applications

// ClassA
public function test(\DateTimeInterface $time): void
{
}
// ClassB
$a = new ClassA();
$a->test(new \DateTimeImmutable());

The above results in:

ERROR: InvalidArgument - src/A.php:x:x - Argument 1 of ClassA::test expects DateTimeInterface, DateTimeImmutable provided
        $a->(new \DateTimeImmutable());

May be related to issue #2933 although I have not had a chance to dig into it.

@psalm-github-bot
Copy link

Hey @jrushlow, can you reproduce the issue on https://psalm.dev ?

@jrushlow
Copy link
Author

jrushlow commented Mar 9, 2020

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/da2890ba9e
<?php

function test(\DateTimeInterface $time): void
{
}

test(new \DateTimeImmutable);
Psalm output (using commit a0da735):

INFO: UnusedParam - 3:34 - Param $time is never referenced in this method

ERROR: InvalidArgument - 7:6 - Argument 1 of test expects DateTimeInterface, DateTimeImmutable provided

@muglug
Copy link
Collaborator

muglug commented Mar 9, 2020

ah right, thanks, broken an hour ago by 40a7a11

@jrushlow
Copy link
Author

jrushlow commented Mar 9, 2020

thanks for the quick fix!

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

2 participants