Skip to content

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

@gnutix

Description

@gnutix

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions