phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Add `Type::popArray()` and `Type::shiftArray()`

Open herndlm opened this issue 3 years ago • 1 comments

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.

herndlm avatar Oct 14 '22 19:10 herndlm

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 mixed instead of 'foo' because $queue becomes NeverType in 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, now NeverType::popArray() results in mixed.~~ 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

herndlm avatar Oct 14 '22 22:10 herndlm

Thank you.

ondrejmirtes avatar Oct 16 '22 11:10 ondrejmirtes

@herndlm did you intentiomally not use the new Type methods in the array-pop and array-shift return type extension?

staabm avatar Oct 16 '22 14:10 staabm

Yes, because those return the first or last element. I mixed this up recently as well :)

herndlm avatar Oct 16 '22 15:10 herndlm