Skip to content

zero times INF should be narrower than mixed #13097

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

Open
mind-bending-forks opened this issue May 31, 2025 · 1 comment · May be fixed by phpstan/phpstan-src#4040
Open

zero times INF should be narrower than mixed #13097

mind-bending-forks opened this issue May 31, 2025 · 1 comment · May be fixed by phpstan/phpstan-src#4040

Comments

@mind-bending-forks
Copy link

mind-bending-forks commented May 31, 2025

Bug report

If you multiply -1 and INF, the returned type is -INF. This is okay. If you multiply 1 and INF, the returned type is INF. This is okay. However, if you multiply 0 and INF, the returned type is mixed.

https://phpstan.org/r/ab49cb02-8fea-4af2-b934-79ada367618f

I think this is a bug. mixed is too wide.

Code snippet that reproduces the problem

https://phpstan.org/r/ab49cb02-8fea-4af2-b934-79ada367618f

Expected output

The result of multiplying 0 and INF, as interpreted by php when executing var_dump(0*INF); is float(NAN). I think the phpstan type should be float, or the more specific type NAN.

To highlight the inconsistency, if you multiply an integer and INF, you might think that phpstan would return mixed to be consistent with the above, since 0 is in the set of all integers. However, phpstan thinks this is a float.

https://phpstan.org/r/b5d371cb-8026-4388-882d-ec709df94308

... but if you limit the integers to a specific set that includes 0 (e.g. -1|0|1), it does return mixed...

https://phpstan.org/r/44f43ecd-f086-49fe-9554-5e2915a22223

whereas perhaps it should return -INF|NAN|INF or float for this specific example.

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

Yes.

@VincentLanglet
Copy link
Contributor

Logic is inside the ConstantTypeHelper

Seems like it was a wanted behavior https://github.com/phpstan/phpstan-src/blob/504914345cb21a336c195288184db5dd252f5bfb/src/Type/ConstantTypeHelper.php#L37-L39
coming from
phpstan/phpstan-src@29fcf80

But I don't find any NAN occurences in the PHPStan code now, so we might try to remove this check.

@VincentLanglet VincentLanglet linked a pull request Jun 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants