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

Incorrect "negated boolean expression is always false" with boolean comparison of variadic parameter and "treatPhpDocTypesAsCertain: false" #6393

Closed
ilmiont opened this issue Jan 17, 2022 · 3 comments

Comments

@ilmiont
Copy link

ilmiont commented Jan 17, 2022

Bug report

Reproduced in latest PHPStan v1.4.1.

When a function has a variadic parameter, that parameter is typed as an object, and treatPhpDocTypesAsCertain: false is used, PHPStan seems to incorrectly believe that the array created from the variadic parameter values will be non-empty.

Code snippet that reproduces the problem

Playground test case

https://phpstan.org/r/9c91108d-fdf7-44a0-8710-4549a756684d

Expected output

No error should be thrown on line 10. It is valid to call sayHello() with no parameters, and then an empty $people array would be created.

If you enable the "Treat PHPDoc types as certain" flag, the correct behaviour is used.

In addition, if you change the type of $people to a scalar type, the correct behaviour is used.

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

PHPStan has transformed the PHP community and my confidence in my work. Huge thanks to all involved.

@ilmiont ilmiont changed the title Incorrect "negated boolean expression is always false" with variadic parameter and "treatPhpDocTypesAsCertain: false" Incorrect "negated boolean expression is always false" when checking if array created from variadic parameter is empty with "treatPhpDocTypesAsCertain: false" Jan 17, 2022
@canvural
Copy link
Contributor

Related or maybe duplicate of #5698 ?

@ilmiont ilmiont changed the title Incorrect "negated boolean expression is always false" when checking if array created from variadic parameter is empty with "treatPhpDocTypesAsCertain: false" Incorrect "negated boolean expression is always false" with boolean comparison of variadic parameter and "treatPhpDocTypesAsCertain: false" Jan 17, 2022
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@a5447db

@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 Feb 19, 2022
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

3 participants