bugfix: don't consider shortening variables with use statements #5465
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.
Overview
Fixes #5464
There was a bug in the logic that considers when/where to place
use
statements that was causing occasional misprinting of code. This PR fixes the bug and adds a regression test.Implementation notes
Removed line of code that treated variables as targets for
use
-statement insertion.For example, we'd previously consider shortening a variable
foo.bar.baz
tobar.baz
(via ause foo bar.baz
) orbaz
(via ause foo.bar baz
). Now, we'll leave variables likefoo.bar.baz
alone.There may be an even smarter fix that safely inserts
use
to shorten variable names... but perhaps that could be implemented separately from the immediate bugfix. I also think it's probably fine to restrictuse
to shortening names for external references, not local variables (as this PR implements).Test coverage
Transcript added, failing in first commit