phpstan-src
phpstan-src copied to clipboard
Add `Type::popArray()` and `Type::shiftArray()`
This is a boring one, but at least I could get rid of the TypeTraverser usage. I should have never added that..
I wasn't sure at first, but indeed, array_shift re-indexes the array and preserves the list.
oh, this is more interesting after all..
here are 2 failures
- ~~https://github.com/phpstan/phpstan-src/blob/1.8.9/tests/PHPStan/Analyser/data/bug-3875.php#L13 is
mixedinstead of'foo'because$queuebecomesNeverTypein the second iteration of the loop after https://github.com/phpstan/phpstan-src/blob/1.8.9/src/Analyser/NodeScopeResolver.php#L959. This is not the case with other types of loops, so it must be a do-while problem. That type was just passed through via array_pop handling before, nowNeverType::popArray()results inmixed.~~ fixed by adapting do-while handling - ~~https://github.com/phpstan/phpstan-src/blob/1.8.9/tests/PHPStan/Analyser/data/bug-3993.php#L20 is loosing the subtracted type because mixed is not passed through any more. I need to think about what should happen with subtracted types I guess.~~ irrelevant because of new MixedType handling
Thank you.
@herndlm did you intentiomally not use the new Type methods in the array-pop and array-shift return type extension?
Yes, because those return the first or last element. I mixed this up recently as well :)