phpstan / phpstan

PHP Static Analysis Tool - discover bugs in your code without running it!
https://phpstan.org/
MIT License
12.99k stars 888 forks source link

missing "is always true" after property narrowing #12072

Open staabm opened 2 hours ago

staabm commented 2 hours ago

Bug report

I think we are missing a "will always evaluate to true" error after narrowing a property

Code snippet that reproduces the problem

https://phpstan.org/r/1e62658b-0a57-42a6-8de1-42d346c2947f

Expected output

error at line 24, similar to the already reported error at line 29

Did PHPStan help you today? Did it make you happy in any way?

No response

ondrejmirtes commented 2 hours ago

AFAIK this is a feature. In ImpossibleCheckTypeHelper there's something like isSpecified($expr) - return null.

This is to make unit test analysis less annoying.

staabm commented 2 hours ago

AFAIK this is a feature

I am fine with whatever category this report belongs to ;-)

This is to make unit test analysis less annoying.

what do you think about adding something similar as ClassTypeDetector or MethodTypeDetector - so a mean to differentiate test-code from other code?