Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

non-empty-list<...> does not accept list<...> #13498

Unanswered
tg666 asked this question in Support
Discussion options

Hi, I have found a case where PHPStan is reporting something that I believe to be incorrect.

https://phpstan.org/r/ab12465b-7e14-4433-8c1d-64ea5fa212d6

The condition at the beginning of the method ensures that there are at least two items in the $branches property, meaning that the result of array_pop() will again be non-empty-list.

Is this a bug, or is there a way to solve this problem?
Thank you for your help.

You must be logged in to vote

Replies: 1 comment

Comment options

Interestingly, adding assert(count($this->branches) === 2); before the array_pop() fixes it.

Using a value of 1 or less causes it to (rightfully) complain.

However, using assert(count($this->branches) > 1); (or >= 2 etc) doesn't work. 🤔 Maybe it relates to the issue with the count() guard not narrowing the type enough?


I'm not sure it's a bug, maybe it's a missing feature. AFAIK PHPStan cannot model N-size lists. You can see that by putting PHPStan\dumpType() in a few places and see how the type doesn't change.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /