phpstan icon indicating copy to clipboard operation
phpstan copied to clipboard

Deep branching leads to variable might not be defined

Open Khez opened this issue 2 years ago • 4 comments

Bug report

Line 19: Dumped type: true
Line 19: Variable $doSomething might not be defined.
Line 38: Dumped type: true

Code snippet that reproduces the problem

https://phpstan.org/r/66abf983-3208-448e-97c7-ceebf47bee03

Expected output

Line 19: Dumped type: true
Line 38: Dumped type: true

Khez avatar Jun 21 '22 10:06 Khez

Is anyone actively working on this?

If not can I take a crack at it ? Any guidance would be appreciated on what practices you use during development :)

Khez avatar Jul 05 '22 12:07 Khez

Is anyone actively working on this? If not can I take a crack at it ?

most likely not if it's sitting there for 2 weeks, I'd say give it a go!

Any guidance would be appreciated on what practices you use during development :)

I guess everyone does it different, what I do is I mostly start with a failing test for that specific rule using the snippet from here. If I don't know which rule it is I often temporarily add a AnalyserIntegrationTest which I then migrate to the specific rule test. And then, moslty I work with the debugger to find where it happens. Often general things like that are in TypeSpecifier, NodeScopeResolver or MutatingScope

herndlm avatar Jul 05 '22 12:07 herndlm

My main thoughts were to find where Scope resolving was diverging between the above two test scenarios.

Tried to get a patch in but the issue seems deeper than anticipated.

If anyone wants to take this task head on, please do so!

Khez avatar Jul 19 '22 20:07 Khez

Switch statement is handled here: https://github.com/phpstan/phpstan-src/blob/9a6ded56aa8db7d76201a55b5a0c7711e554b484/src/Analyser/NodeScopeResolver.php#L1111-L1177

ondrejmirtes avatar Jul 20 '22 11:07 ondrejmirtes