phpstan / phpstan-webmozart-assert

PHPStan extension for webmozart/assert
MIT License
165 stars 28 forks source link

Support isMap, adapt isList to work the same #101

Closed herndlm closed 2 years ago

herndlm commented 2 years ago

This is currently not working, the SpecifiedTypes look a bit odd. e.g. in case of passing mixed to isMap:

image

Could this be a bug on type specification or can you see something that I'm doing wrong @ondrejmirtes?

If i use an array as input (passing mixed[]) it starts working suddenly, not sure why. e.g. with an array passed

image

I kept staring at the expression and compared it to something generated with php-parser, but it looks fine to me. Well, I'll take another look later..

ah yeah and the expression type handling in general is fine of course: https://phpstan.org/r/43b72845-d649-4a60-8953-afc24cfaaf39

UPDATE: ok, the main problem seems to be the independent type specification of the left and right expression. And the right one kind of already needs the info from the left one (that the input is an array). without it, it finds (array|null) as return type of array_filter being called with mixed hmm 🤔

UDPATE2: hah, the resolved type in the scope is odd, after specifiny the left expression. maybe that's it?! it seems to be somewhere overriden or does not remember it's value. I was interrupted and need to debug this deeper later..

image
ondrejmirtes commented 2 years ago

Thank you!