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 when comparing two variables to null and using the other #4326

Closed
gnutix opened this issue Jan 6, 2021 · 3 comments
Closed

Comments

@gnutix
Copy link

gnutix commented Jan 6, 2021

Bug report

If you have two nullable variables, and you first check that both are null (and if so break/return/throw), then check if one is null and use the other, it should report that the "other" can be null.

Code snippet that reproduces the problem

With return : https://phpstan.org/r/a3327010-6db9-4d2e-bb4a-0ff19378de1d
With throw : https://phpstan.org/r/3eb7a19d-7fc1-49e9-8cde-411d06b1fd3d

Expected output

There should be no errors.

@phpstan-bot
Copy link
Contributor

@gnutix After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-11: Method HelloWorld::sayHello() should return string but returns string|null.
+No errors

@phpstan-bot
Copy link
Contributor

@gnutix After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-11: Method HelloWorld::sayHello() should return string but returns string|null.
+No errors

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants