Skip to content

Commit 5c0fc1f

Browse files
committed
C#: Add BMN tests for cs/constant-condition.
1 parent 431586b commit 5c0fc1f

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
3+
partial class C1
4+
{
5+
public C2 Prop { get; set; }
6+
}
7+
8+
class C2 { }
9+
10+
class ConstantMatching
11+
{
12+
void M1()
13+
{
14+
var c1 = new C1();
15+
if (c1.Prop is int) // $ Alert
16+
{
17+
}
18+
19+
// Should not be considered a constant condition as
20+
// we don't know anything about D.
21+
var d = new D();
22+
if (d.Prop is C2) // $ Alert
23+
{
24+
}
25+
}
26+
}
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| ConstantCondition.cs:15:13:15:26 | ... is ... | Condition always evaluates to 'false'. |
2+
| ConstantCondition.cs:15:24:15:26 | access to type Int32 | Pattern never matches. |
3+
| ConstantCondition.cs:22:13:22:24 | ... is ... | Condition always evaluates to 'false'. |
4+
| ConstantCondition.cs:22:23:22:24 | access to type C2 | Pattern never matches. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: Bad Practices/Control-Flow/ConstantCondition.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --standalone

0 commit comments

Comments
 (0)