提交 c606a541 编写于 作者: M Manish Vasani

Fix the core issue reported in #30397.

上级 a80c765d
......@@ -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(
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册