phpstan
phpstan copied to clipboard
Deep branching leads to variable might not be defined
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
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 :)
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
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!
Switch statement is handled here: https://github.com/phpstan/phpstan-src/blob/9a6ded56aa8db7d76201a55b5a0c7711e554b484/src/Analyser/NodeScopeResolver.php#L1111-L1177