SubNodeNames are known at static analysis time#1035
SubNodeNames are known at static analysis time#1035staabm wants to merge 1 commit intonikic:masterfrom
Conversation
|
I can kind of see how this could be useful in theory, but it's not really clear to me where we'd see a benefit in practice. Can you share an example where e.g. this gets rid of a baseline suppression in phpstan-src or similar? |
|
see e.g. https://phpstan.org/r/9041358f-043d-4171-9780-f9d9b4b3c534 before this PR here, the unused property cannot be detected. after this PR we get
I can't give you such a example, as because of the dynamic use errors are not detected which would be otherwise. |
|
hmm.. I tried this PR on the whole phpstan-src codebase and it somehow has strange side-effects. I have another look |
9a5b30d to
a73955f
Compare
| /** @var Node\Stmt[] Statements */ | ||
| public array $stmts; | ||
|
|
||
| private const SUBNODE_NAMES = ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts']; |
There was a problem hiding this comment.
It would be great to assert the lists with a test, so the lists are never outdated/incomplete.
this PR turns the SubNodeNames into constant arrays and corresponding phpdocs, which makes them available to PHPStan at static analysis time.
this information is useful to better cover codebases which utilize PHP-Parser and in need of dynamic property lookups like
when the type of
$nodeis known.closes #1033