C#: Remove false positives in cs/constant-condition

This commit is contained in:
Tom Hvitved
2019-06-28 11:34:43 +02:00
parent 4da7a17f4b
commit db565c5a88
3 changed files with 8 additions and 1 deletions

View File

@@ -4,6 +4,7 @@
| **Query** | **Expected impact** | **Change** |
|------------------------------|------------------------|-----------------------------------|
| Constant condition (`cs/constant-condition`) | Fewer false positive results | Results have been removed for default cases (`_`) in switch expressions. |
| Dispose may not be called if an exception is thrown during execution (`cs/dispose-not-called-on-throw`) | Fewer false positive results | Results have been removed where an object is disposed both by a `using` statement and a `Dispose` call. |
## Changes to code extraction

View File

@@ -101,6 +101,13 @@ class ConstantMatchingCondition extends ConstantCondition {
)
}
override predicate isWhiteListed() {
exists(SwitchExpr se |
se.getACase().getPattern() = this.(DiscardExpr) and
strictcount(se.getACase()) > 1
)
}
override string getMessage() {
if b = true then result = "Pattern always matches." else result = "Pattern never matches."
}

View File

@@ -8,7 +8,6 @@
| ConstantCondition.cs:66:18:66:18 | 3 | Pattern always matches. |
| ConstantCondition.cs:77:18:77:20 | access to type Int32 | Pattern never matches. |
| ConstantCondition.cs:97:13:97:13 | _ | Pattern always matches. |
| ConstantCondition.cs:106:13:106:13 | _ | Pattern always 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'. |