Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Remove redundant assignment" removes unrelated code #72829

Closed
vsfeedback opened this issue Apr 1, 2024 · 2 comments · Fixed by #75952
Closed

"Remove redundant assignment" removes unrelated code #72829

vsfeedback opened this issue Apr 1, 2024 · 2 comments · Fixed by #75952
Labels
Area-IDE Bug Feature - IDE0059 Unused value help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
If I use the Quick Action IDE0059 "Remove redundant assignement" with a particular setup, it will erroneously remove unrelated code and break logic. This is the problematic code setup:

DynamicBuffer<Entity> items = default;
if (SimWorldReader.Common_TryGetInventoryBuffer(..., out items))
{
    ...
}

using var _ = ListPool<DisplayedItemData>.Get(out var displayedInventory);

If I use IDE0059 on the variable items, it will correctly remove = default, but it will also erroneously remove using var _ = a few lines below, which breaks the code logic. using var _ is not a redundant assignment and it is needed to dispose of the ListPool<DisplayedItemData>.Get(..) return value.

This is a dangerous bug because it alters the logic of the code without telling you.


Original Comments

Feedback Bot on 3/28/2024, 10:19 PM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 1, 2024
@sharwell sharwell added Feature - IDE0059 Unused value Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 5, 2024
@sharwell sharwell added this to the Backlog milestone Apr 5, 2024
@github-project-automation github-project-automation bot moved this to InQueue in Small Fixes Aug 28, 2024
obonn1 pushed a commit to obonn1/roslyn that referenced this issue Nov 18, 2024
- Adds a test to ensure redundant assignment removal respects the `using var` statement.
- Relates to issue dotnet#72829.
@obonn1
Copy link
Contributor

obonn1 commented Nov 18, 2024

I figured I'd take a crack at this as it seemed simple enough for a first contribution. I'm unsure how to link my PR to the work item.

@jnm2
Copy link
Contributor

jnm2 commented Nov 18, 2024

obonn1 pushed a commit to obonn1/roslyn that referenced this issue Nov 18, 2024
- Adds a test to ensure redundant assignment removal respects the `using var` statement.
- closes issue dotnet#72829.
@github-project-automation github-project-automation bot moved this from InQueue to Completed in Small Fixes Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Feature - IDE0059 Unused value help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

4 participants