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 NAN and NAN will always evaluate to false #10297

Closed
gnutix opened this issue Dec 13, 2023 · 5 comments
Closed
Labels
Milestone

Comments

@gnutix
Copy link

gnutix commented Dec 13, 2023

Bug report

Hello there!

I've just upgraded to the latest and greatest version of PHPStan (1.10.50) and this issue appeared :

Parameter #1 $array of function collectWithKeys expects array<'Not a Number', NAN>, array{Not a Number: NAN} given.

Code snippet that reproduces the problem

https://phpstan.org/r/8b7e5238-b4a6-46c9-9fc3-0ef7c3b2343e

Expected output

There should be no errors.

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

It allowed me to fix quite a lot of wrong PHPDocs ! 💪 Thank you for this invaluable tool.

@ondrejmirtes
Copy link
Member

I think the underlying issue is simply this: https://phpstan.org/r/5cff9af9-ecef-422d-8a7b-606e25c33b78

And must be fixed in ConstantFloatType in accepts and isSuperTypeOf methods.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 13, 2023
@gnutix gnutix changed the title NAN not properly dealt with in bleeding edge ? Strict comparison using === between NAN and NAN will always evaluate to false Dec 13, 2023
@LeoVie
Copy link

LeoVie commented Feb 15, 2024

I think the underlying issue is simply this: https://phpstan.org/r/5cff9af9-ecef-422d-8a7b-606e25c33b78

Isn't this behaviour correct, as NAN === NAN will indeed always evaluate to false?

https://3v4l.org/ACgGt

@phpstan-bot
Copy link
Contributor

@ondrejmirtes @LeoVie After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
+7: Expression "\NAN === \NAN" on a separate line does not do anything.
 7: Strict comparison using === between NAN and NAN will always evaluate to false.
Full report
Line Error
7 Expression "\NAN === \NAN" on a separate line does not do anything.
7 Strict comparison using === between NAN and NAN will always evaluate to false.

@ondrejmirtes
Copy link
Member

Fixed phpstan/phpstan-src#3036

Copy link

github-actions bot commented Jun 4, 2024

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

No branches or pull requests

4 participants