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

Improve dead code detection after nested function calls with conditional never return type

Open rvanvelzen opened this issue 3 years ago • 2 comments

Partial solution for phpstan/phpstan#7188: check expressions for terminating calls a bit more aggressively.

rvanvelzen avatar Jun 01 '22 06:06 rvanvelzen

I think that correct solution would be to handle this similarly to $hasYield and $throwPoints - to collect this information in ExpressionResult and StatementResult. In the end findEarlyTerminatingExpr wouldn't be needed at all.

Another similar data like this to gather is "purity" - "is this expression/statement pure or not?" It's unrelated to this PR, I'm just saying is another thing that should be done in the future, to solve https://github.com/phpstan/phpstan/issues/4426 :)

ondrejmirtes avatar Jun 01 '22 06:06 ondrejmirtes

That seems like a good idea - I'll look into it.

rvanvelzen avatar Jun 01 '22 06:06 rvanvelzen

I've reduced it to a much simpler version that does the trick as well.

rvanvelzen avatar Sep 02 '22 06:09 rvanvelzen

Of course, this makes sense :) Thank you.

ondrejmirtes avatar Sep 02 '22 15:09 ondrejmirtes