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

Handle using var in redundant assignment removal #75952

Merged

Conversation

obonn1
Copy link
Contributor

@obonn1 obonn1 commented Nov 18, 2024

On changing an unused variable to discard CSharpReplaceDiscardDeclarationsWithAssignmentsService.ReplaceAsync() ensures that instead of local declarations, simple discards are used. Without an exception for using statements, this end up changing using var _ within the scope to be replaced with _ regardless of any relation to the variable targeted by the suggestion. This change adds a filter to the method, preserving using statements and the disposal they provide.

@obonn1 obonn1 requested a review from a team as a code owner November 18, 2024 01:39
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 18, 2024
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Nov 18, 2024
@obonn1 obonn1 marked this pull request as draft November 18, 2024 01:41
@obonn1
Copy link
Contributor Author

obonn1 commented Nov 18, 2024

@dotnet-policy-service agree

@obonn1 obonn1 marked this pull request as ready for review November 18, 2024 01:44
- Adds a test to ensure redundant assignment removal respects the `using var` statement.
- closes issue dotnet#72829.
@obonn1 obonn1 force-pushed the feature/fix-redundant-assignment-bug branch from 23a9d95 to 3d59049 Compare November 18, 2024 02:23
@CyrusNajmabadi CyrusNajmabadi enabled auto-merge (squash) November 18, 2024 03:30
@CyrusNajmabadi
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Remove redundant assignment" removes unrelated code
3 participants