Skip to content

Commit 7c759da

Browse files
committed
Fix CA1508 false positive for pattern expressions
Fixes #6048 `goto case DiscardPattern` had the required logic for setting the predicated value the pattern value in true branch of is expression, but it was also setting `predicateValueKind`, which is in turn used to identify redundant duplicate conditional checks. Latter is fixed by this change.
1 parent 62b7d16 commit 7c759da

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Utilities/FlowAnalysis/FlowAnalysis/Framework/DataFlow/DataFlowOperationVisitor.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,14 @@ private void PerformPredicateAnalysisCore(IOperation operation, TAnalysisData ta
15641564
predicateValueKind = SetValueForIsNullComparisonOperator(isPatternOperation.Pattern, equals: FlowBranchConditionKind == ControlFlowConditionKind.WhenFalse, targetAnalysisData: targetAnalysisData);
15651565
}
15661566

1567-
// Also set the predicated value for pattern value for true branch, i.e. for 'c' in "c is D d".
1568-
goto case OperationKind.DiscardPattern;
1567+
// Also set the predicated value for pattern value for true branch, i.e. for 'c' in "c is D d",
1568+
// while explicitly ignore the returned 'predicateValueKind'.
1569+
if (FlowBranchConditionKind == ControlFlowConditionKind.WhenTrue)
1570+
{
1571+
_ = SetValueForIsNullComparisonOperator(isPatternOperation.Value, equals: false, targetAnalysisData: targetAnalysisData);
1572+
}
1573+
1574+
break;
15691575

15701576
case OperationKind.DiscardPattern:
15711577
case OperationKind.RecursivePattern:

0 commit comments

Comments
 (0)