Skip to content

Commit 3e563f7

Browse files
committed
C#: Add (failing) unit test for cs/constant-condition
1 parent e88e5cf commit 3e563f7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

csharp/ql/test/query-tests/Bad Practices/Control-Flow/ConstantCondition/ConstantCondition.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ void M2(int i)
5050
j = (int?)i ?? 1; // BAD
5151
s = ""?.CommaJoinWith(s); // BAD
5252
s = s ?? ""; // GOOD
53+
s = (i==0 ? s : null) ?? s; // BAD (False positive)
5354
}
5455
}
5556

csharp/ql/test/query-tests/Bad Practices/Control-Flow/ConstantCondition/ConstantCondition.expected

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
| ConstantCondition.cs:49:17:49:18 | "" | Expression is never 'null'. |
55
| ConstantCondition.cs:50:13:50:19 | (...) ... | Expression is never 'null'. |
66
| ConstantCondition.cs:51:13:51:14 | "" | Expression is never 'null'. |
7-
| ConstantCondition.cs:62:18:62:18 | 2 | Pattern never matches. |
8-
| ConstantCondition.cs:64:18:64:18 | 3 | Pattern always matches. |
9-
| ConstantCondition.cs:75:18:75:20 | access to type Int32 | Pattern never matches. |
7+
| ConstantCondition.cs:53:25:53:28 | null | Expression is always 'null'. |
8+
| ConstantCondition.cs:63:18:63:18 | 2 | Pattern never matches. |
9+
| ConstantCondition.cs:65:18:65:18 | 3 | Pattern always matches. |
10+
| ConstantCondition.cs:76:18:76:20 | access to type Int32 | Pattern never matches. |
1011
| ConstantConditionBad.cs:5:16:5:20 | ... > ... | Condition always evaluates to 'false'. |
1112
| ConstantConditionalExpressionCondition.cs:11:22:11:34 | ... == ... | Condition always evaluates to 'true'. |
1213
| ConstantConditionalExpressionCondition.cs:12:21:12:25 | false | Condition always evaluates to 'false'. |

0 commit comments

Comments
 (0)