From c606a541895b7cfb672e5cc1be3312797829d744 Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Tue, 9 Oct 2018 13:09:12 -0700 Subject: [PATCH] Fix the core issue reported in #30397. --- .../RemoveUnusedMembers/RemoveUnusedMembersTests.cs | 3 +++ .../AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs b/src/EditorFeatures/CSharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs index c5e443a15ab..dc06e92453c 100644 --- a/src/EditorFeatures/CSharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs +++ b/src/EditorFeatures/CSharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs @@ -6,6 +6,7 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; +using Roslyn.Test.Utilities; using Xunit; using static Roslyn.Test.Utilities.TestHelpers; @@ -1076,6 +1077,7 @@ int Goo } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedMembers)] + [WorkItem(30397, "https://github.com/dotnet/roslyn/issues/30397")] public async Task FieldIsIncrementedAndValueUsed() { await TestDiagnosticMissingAsync( @@ -1087,6 +1089,7 @@ public async Task FieldIsIncrementedAndValueUsed() } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnusedMembers)] + [WorkItem(30397, "https://github.com/dotnet/roslyn/issues/30397")] public async Task FieldIsIncrementedAndValueUsed_02() { await TestDiagnosticMissingAsync( diff --git a/src/Features/Core/Portable/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs b/src/Features/Core/Portable/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs index d7afadacdc2..ab41e5d6765 100644 --- a/src/Features/Core/Portable/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs +++ b/src/Features/Core/Portable/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs @@ -194,7 +194,7 @@ private void AnalyzeMemberReferenceOperation(OperationAnalysisContext operationC compoundAssignment.Target == memberReference || memberReference.Parent is IIncrementOrDecrementOperation); - // Compound assignment or increment whose value is being dropped (parent has null type) + // Compound assignment or increment whose value is being dropped (parent is an expression statement) // is treated as a Write as the value was never actually 'read' in a way that is observable. // // Consider the following example: @@ -209,7 +209,7 @@ private void AnalyzeMemberReferenceOperation(OperationAnalysisContext operationC // while the increment operation '_f2++' is child of a return statement, which uses the result of the increment. // For the above test, '_f1' can be safely removed without affecting the semantics of the program, while '_f2' cannot be removed. - if (memberReference.Parent.Parent?.Type == null) + if (memberReference.Parent.Parent is IExpressionStatementOperation) { valueUsageInfo = ValueUsageInfo.Write; } -- GitLab