-
-
Notifications
You must be signed in to change notification settings - Fork 932
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
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.
Beta Was this translation helpful? Give feedback.