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 is broadened to bool when passed as argument #8876

Closed
Csardelacal opened this issue Feb 10, 2023 · 2 comments
Closed

False is broadened to bool when passed as argument #8876

Csardelacal opened this issue Feb 10, 2023 · 2 comments

Comments

@Csardelacal
Copy link

Bug report

When a function receives false as a parameter to a call that is using a template, false is treated as bool. This is very prominent in optional functions that return a second value if the first one does not fulfill a condition.

Code snippet that reproduces the problem

https://phpstan.org/r/f005b006-ae63-4d4e-8b78-7e7e802f53a7

Expected output

I think this code should pass. I understand why PHPStan assumes that a parameter with a false value is a boolean, but since it is (in the example) never true, it could just as well be treated as false.

Did PHPStan help you today? Did it make you happy in any way?

Yes. PHPStan is like the three reviewers I do not have. <3

@ondrejmirtes
Copy link
Member

Duplicate of #7944

But you can solve your issue with a conditional type instead of generics: https://phpstan.org/writing-php-code/phpdoc-types#conditional-return-types

@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 Mar 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants