C#: Include normal switch/case statements in the white list and allow the use of wildcards when there is a condition.

This commit is contained in:
Michael Nebel
2025-03-11 14:37:56 +01:00
parent c15137e992
commit 150aa5d1cf

View File

@@ -119,9 +119,14 @@ class ConstantMatchingCondition extends ConstantCondition {
}
override predicate isWhiteListed() {
exists(SwitchExpr se, int i |
se.getCase(i).getPattern() = this.(DiscardExpr) and
i > 0
exists(Switch se, Case c, int i | c = se.getCase(i) |
c.getPattern() = this.(DiscardExpr) and
(
i > 0
or
i = 0 and
exists(Expr cond | c.getCondition() = cond and not isConstantCondition(cond, true))
)
)
or
this = any(PositionalPatternExpr ppe).getPattern(_)