Skip to content

Commit

Permalink
Merge pull request #6608 from CollinAlpert/issue_6532
Browse files Browse the repository at this point in the history
Fix CA1508 for compound assignments
  • Loading branch information
mavasani committed Jul 13, 2023
2 parents f356758 + 52eee0e commit 0d3a2bb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3184,5 +3184,47 @@ static void Filter(List<Data> list, int j)
}
");
}

[Trait(Traits.DataflowAnalysis, Traits.Dataflow.ValueContentAnalysis)]
[Trait(Traits.DataflowAnalysis, Traits.Dataflow.CopyAnalysis)]
[Fact, WorkItem(6532, "https://github.com/dotnet/roslyn-analyzers/issues/6532")]
public Task TestTernaryOperator_NoDiagnosticAsync()
{
return VerifyCSharpAnalyzerAsync(@"
using System.Collections.Generic;
class Test
{
void M()
{
var i = 0;
i += M2() ? 1 : 0;
_ = i != 0;
}
bool M2() => true;
}");
}

[Trait(Traits.DataflowAnalysis, Traits.Dataflow.ValueContentAnalysis)]
[Trait(Traits.DataflowAnalysis, Traits.Dataflow.CopyAnalysis)]
[Fact, WorkItem(6532, "https://github.com/dotnet/roslyn-analyzers/issues/6532")]
public Task TestTernaryOperator2_NoDiagnosticAsync()
{
return VerifyCSharpAnalyzerAsync(@"
using System.Collections.Generic;
class Test
{
void M()
{
var i = 1;
i += M2() ? 1 : 0;
_ = i != 2;
}
bool M2() => true;
}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,15 @@ public override TAbstractAnalysisValue VisitCompoundAssignment(ICompoundAssignme
TAbstractAnalysisValue targetValue = Visit(operation.Target, argument);
TAbstractAnalysisValue assignedValue = Visit(operation.Value, argument);
var value = ComputeValueForCompoundAssignment(operation, targetValue, assignedValue, operation.Target.Type, operation.Value.Type);
SetAbstractValueForAssignment(operation.Target, operation.Value, value);
if (operation.Target is IFlowCaptureReferenceOperation flowCaptureReference)
{
HandleFlowCaptureReferenceAssignment(flowCaptureReference, operation.Value, value);
}
else
{
SetAbstractValueForAssignment(operation.Target, operation.Value, value);
}

return value;
}

Expand Down

0 comments on commit 0d3a2bb

Please sign in to comment.