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
"expects float, float|null given" error not triggered when it should #4789
Comments
Hi, so you expect errors on lines 34 and 37? FYI this change has not been released yet, it's only in dev-master, and you can force the old behaviour by using |
@ondrejmirtes Wait... new phpstan assumes methods to be pure? Why? 🤔 |
It's only in bleeding edge, see the difference here: https://phpstan.org/r/29da7f5c-ca5d-45b7-bb95-c7e9df41b348 vs. https://phpstan.org/r/6744da50-73f8-45d4-9d90-341c02b9486f It eliminates a lot of false-positives, the list of fixed issues is long:
The state of object is forgotten if you call an impure method on it, or pass it to an impure method or function. There's going to be an article about this published before the next release is out. |
@ondrejmirtes Thanks for the explanation 👍 |
I see. Thanks @ondrejmirtes! |
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. |
Bug report
In case method returns
float|null
and you check that the result is not null and then use the method again, phpstan should display an error. IIRC this was working properly in past versions.Code snippet that reproduces the problem
https://phpstan.org/r/8b9b18a1-5a4f-4cc2-a35b-96615bd0c6eb
Expected output
Line 32 correctly triggers
Parameter #1 $total of method Invoice::checkTotal() expects float, float|null given.
, but the same error should be triggered on lines 34 and 37.The text was updated successfully, but these errors were encountered: