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

Strict comparison using !== between xxx|void and null will always evaluate to true. #9388

Closed
mvorisek opened this issue Jun 4, 2023 · 7 comments

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Jun 4, 2023

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/e8b73d6d-a543-48d1-a67c-dd6a4b6036d1

Expected output

no phpstan error, the condition is clearly not always true, as void returns natively/implicitly null

when Closure result is assigned, check for void - https://phpstan.org/r/bc2bb528-17b2-4976-81f2-6187b60e3e14 - is correct, but if void is part of an union, void should be converted to null internally probably

@ondrejmirtes
Copy link
Member

void makes sense only as a standalone type, not in a union. Your example is even a compile-time error in PHP: https://3v4l.org/LCRng

This is the correct code: https://phpstan.org/r/891c379d-38f9-4493-ab0a-f22783aec94a

@mvorisek
Copy link
Contributor Author

mvorisek commented Jun 5, 2023

Thank you, you are right with the native type, but how to allow passing Closure that can return nothing - https://phpstan.org/r/c67377cf-3b08-4f29-88de-5fdae8a1c157?

@ondrejmirtes
Copy link
Member

The easiest way to pass your code: https://phpstan.org/r/0899c462-60f4-400e-bc7d-ea30298182ef

@mvorisek
Copy link
Contributor Author

mvorisek commented Jun 5, 2023

Please see https://phpstan.org/r/560235d6-759e-45e7-a432-0baf3f09d5a2 and https://3v4l.org/TnQTX .

The php code is valid, phpstan is simply wrong here when the type is unioned. See this issue description for possible fix.

@mvorisek
Copy link
Contributor Author

@ondrejmirtes let say that two types are comming from a local/global aliases - https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases and unioned.

Then this has to be a bug, when unioned type is assigned and there are 2+ Closures with mixed void/non-void return, the voided one must be casted to null as php does natively.

@mvorisek
Copy link
Contributor Author

@ondrejmirtes I would be happy if this issue can be reopened as unioning any 2 Closures should be valid.

@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 Jul 21, 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