C#: Add (failing) unit test for cs/constant-condition

This commit is contained in:
calum
2019-04-01 12:22:42 +01:00
parent e88e5cf4d7
commit 3e563f7a11
2 changed files with 5 additions and 3 deletions

View File

@@ -50,6 +50,7 @@ class ConstantNullness
j = (int?)i ?? 1; // BAD
s = ""?.CommaJoinWith(s); // BAD
s = s ?? ""; // GOOD
s = (i==0 ? s : null) ?? s; // BAD (False positive)
}
}

View File

@@ -4,9 +4,10 @@
| ConstantCondition.cs:49:17:49:18 | "" | Expression is never 'null'. |
| ConstantCondition.cs:50:13:50:19 | (...) ... | Expression is never 'null'. |
| ConstantCondition.cs:51:13:51:14 | "" | Expression is never 'null'. |
| ConstantCondition.cs:62:18:62:18 | 2 | Pattern never matches. |
| ConstantCondition.cs:64:18:64:18 | 3 | Pattern always matches. |
| ConstantCondition.cs:75:18:75:20 | access to type Int32 | Pattern never matches. |
| ConstantCondition.cs:53:25:53:28 | null | Expression is always 'null'. |
| ConstantCondition.cs:63:18:63:18 | 2 | Pattern never matches. |
| ConstantCondition.cs:65:18:65:18 | 3 | Pattern always matches. |
| ConstantCondition.cs:76:18:76:20 | access to type Int32 | Pattern never matches. |
| ConstantConditionBad.cs:5:16:5:20 | ... > ... | Condition always evaluates to 'false'. |
| ConstantConditionalExpressionCondition.cs:11:22:11:34 | ... == ... | Condition always evaluates to 'true'. |
| ConstantConditionalExpressionCondition.cs:12:21:12:25 | false | Condition always evaluates to 'false'. |