Skip to content

Since 2.1.52 nested foreach over non-empty-list<T> narrows accumulated array to exact count #14543

@janedbal

Description

@janedbal

Bug report

  • PHPStan unrolls the known-2-iteration outer loop and treats the inner non-empty-list as exactly 1 element per iteration.

  • Bisected: broke between 2.1.51 and 2.1.52

Code snippet that reproduces the problem

https://phpstan.org/r/94ca6c21-0d2d-49c5-8b07-7ef02077f988

Expected output

non-empty-list<int> (≥ 2 elements — outer loop runs 2 times, each inner iteration adds ≥ 1)

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions