Unused global variable after modification #6129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This would fix #6111 (comment)
This basically registers every global variable and prevent emitting UnusedVariable on those.
This means true positives (where UnusedVariable was emitted and the variable was not used) won't work anymore: https://psalm.dev/r/edb1c159ea. Hence the failing test here
However, this bring the behaviour closer to what already exists for references: https://psalm.dev/r/67292ae85a
Going beyond that would mean Psalm would have to record not only variable read access detecting usage but also write access. This seems a big piece of work for detecting a few globals and references unused.
If this is good enough to be merged, I'll remove the failing test and this will become the new behaviour for those cases.