Skip to content

Handle using var in redundant assignment removal#75952

Merged
CyrusNajmabadi merged 1 commit intodotnet:mainfrom
obonn1:feature/fix-redundant-assignment-bug
Nov 18, 2024
Merged

Handle using var in redundant assignment removal#75952
CyrusNajmabadi merged 1 commit intodotnet:mainfrom
obonn1:feature/fix-redundant-assignment-bug

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
@ghost ghost 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
Contributor

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