Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Incorrectly narrowed to previously asserted type, even if marked impure #13416

@EmielM

Description

@EmielM

Code snippet that reproduces the problem

https://phpstan.org/r/169b87d5-eec8-4c75-abbc-94878970833f

Expected output

The count(MyRecord::find()) type is incorrectly narrowed to 1. It should be non-negative-int again

Impact

In upgrading to phpstan 2, this is hitting a lot of faulty impossibleType in our unit tests, where we have a similar pattern for (mock) records, and count assertions are common. Note it still happens when using $this->assertCount(1, Something::find()); (new Something)->insert(); $this->assertCount(2, Something::find()); in PHPUnit.

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

It makes me want to code in weekends!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions