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

[1.9.0] count() return type is 1 in a loop where the value changes at each iteration #8277

Closed
gnutix opened this issue Nov 3, 2022 · 6 comments · Fixed by phpstan/phpstan-src#1968

Comments

@gnutix
Copy link

gnutix commented Nov 3, 2022

Bug report

Just upgraded PHPStan from 1.8.10 to 1.9.0 (missed 1.8.11) and I get this new inspection in a swindow() function¹ :

Comparison operation ">" between 1 and int<1, max> is always false.

¹: window([1, 2, 3], width: 2); outputs [[1, 2], [2, 3]], only for streams instead of arrays

Code snippet that reproduces the problem

https://phpstan.org/r/1b6492a8-0d46-4789-824a-7e899d2c90c4

Expected output

No error, the return type of count() should be int<1, max> in this case (we know the array as at least one value, nothing more).

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

Thanks a lot for all the hard work on this latest release!

@gnutix gnutix changed the title [1.9.0] count() return type is '1' in a loop where the value changes at each iteration [1.9.0] count() return type is 1 in a loop where the value changes at each iteration Nov 3, 2022
@gnutix gnutix changed the title [1.9.0] count() return type is 1 in a loop where the value changes at each iteration [1.9.0] count() return type is 1 in a loop where the value changes at each iteration Nov 3, 2022
@herndlm
Copy link
Contributor

herndlm commented Nov 3, 2022

Do you remember if you upgraded straight from the latest 1.8 to 1.9? Just trying to figure out if one of my changes broke this 😅

@ondrejmirtes
Copy link
Member

You have the code sample - you can bisect it.

@herndlm
Copy link
Contributor

herndlm commented Nov 3, 2022

I know.. just being lazy here from my phone. Will do that :)

@gnutix
Copy link
Author

gnutix commented Nov 3, 2022

Upgraded from 1.8.10, so I missed 1.8.11.

@herndlm
Copy link
Contributor

herndlm commented Nov 4, 2022

Ladies and gentleman, we have a winner! It is me and I won a bugfix :) The commit that broke this was phpstan/phpstan-src@67819b2

@github-actions
Copy link

github-actions bot commented Dec 7, 2022

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 Dec 7, 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

Successfully merging a pull request may close this issue.

3 participants