Skip to content

Commit 150aa5d

Browse files
committed
C#: Include normal switch/case statements in the white list and allow the use of wildcards when there is a condition.
1 parent c15137e commit 150aa5d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

csharp/ql/src/Bad Practices/Control-Flow/ConstantCondition.ql

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ class ConstantMatchingCondition extends ConstantCondition {
119119
}
120120

121121
override predicate isWhiteListed() {
122-
exists(SwitchExpr se, int i |
123-
se.getCase(i).getPattern() = this.(DiscardExpr) and
124-
i > 0
122+
exists(Switch se, Case c, int i | c = se.getCase(i) |
123+
c.getPattern() = this.(DiscardExpr) and
124+
(
125+
i > 0
126+
or
127+
i = 0 and
128+
exists(Expr cond | c.getCondition() = cond and not isConstantCondition(cond, true))
129+
)
125130
)
126131
or
127132
this = any(PositionalPatternExpr ppe).getPattern(_)

0 commit comments

Comments
 (0)