Skip to content

Commit 7b96f66

Browse files
committed
Also run cs/constant-condition on test for cs/comparison-of-identical-expressions
1 parent 85d800f commit 7b96f66

3 files changed

Lines changed: 38 additions & 30 deletions

File tree

csharp/ql/test/query-tests/CSI/CompareIdenticalValues/CompareIdenticalValues.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,54 @@ class CompareIdenticalValues : Super
1111
{
1212
public void M()
1313
{
14-
if (this.Foo == Foo) ; // $ Alert
15-
if (base.Foo == Foo) ; // $ Alert
14+
if (this.Foo == Foo) ; // $ Alert[cs/comparison-of-identical-expressions]
15+
if (base.Foo == Foo) ; // $ Alert[cs/comparison-of-identical-expressions]
1616
if (Foo == new CompareIdenticalValues().Foo) ;
1717

1818
var x = "Abc";
1919
if (x == "Abc") ;
20-
var temp = x == x; // BAD: but flagged by cs/constant-comparison
20+
var temp = x == x; // $ Alert[cs/constant-condition] // BAD: but flagged by cs/constant-condition
2121

2222
double d = double.NaN;
23-
if (d == d) ; // $ Alert // !double.IsNan(d)
24-
if (d <= d) ; // $ Alert // !double.IsNan(d), but unlikely to be intentional
25-
if (d >= d) ; // $ Alert // !double.IsNan(d), but unlikely to be intentional
26-
if (d != d) ; // $ Alert // double.IsNan(d)
27-
if (d > d) ; // $ Alert // always false
28-
if (d < d) ; // $ Alert // always false
23+
if (d == d) ; // $ Alert[cs/comparison-of-identical-expressions] // !double.IsNan(d)
24+
if (d <= d) ; // $ Alert[cs/comparison-of-identical-expressions] // !double.IsNan(d), but unlikely to be intentional
25+
if (d >= d) ; // $ Alert[cs/comparison-of-identical-expressions] // !double.IsNan(d), but unlikely to be intentional
26+
if (d != d) ; // $ Alert[cs/comparison-of-identical-expressions] // double.IsNan(d)
27+
if (d > d) ; // $ Alert[cs/comparison-of-identical-expressions] // always false
28+
if (d < d) ; // $ Alert[cs/comparison-of-identical-expressions] // always false
2929

3030
float f = float.NaN;
31-
if (f == f) ; // $ Alert // !float.IsNan(f)
32-
if (f <= f) ; // $ Alert // !float.IsNan(f), but unlikely to be intentional
33-
if (f >= f) ; // $ Alert // !float.IsNan(f), but unlikely to be intentional
34-
if (f != f) ; // $ Alert // float.IsNan(f)
35-
if (f > f) ; // $ Alert // always false
36-
if (f < f) ; // $ Alert // always false
31+
if (f == f) ; // $ Alert[cs/comparison-of-identical-expressions] // !float.IsNan(f)
32+
if (f <= f) ; // $ Alert[cs/comparison-of-identical-expressions] // !float.IsNan(f), but unlikely to be intentional
33+
if (f >= f) ; // $ Alert[cs/comparison-of-identical-expressions] // !float.IsNan(f), but unlikely to be intentional
34+
if (f != f) ; // $ Alert[cs/comparison-of-identical-expressions] // float.IsNan(f)
35+
if (f > f) ; // $ Alert[cs/comparison-of-identical-expressions] // always false
36+
if (f < f) ; // $ Alert[cs/comparison-of-identical-expressions] // always false
3737

3838
int i = 0;
39-
if (i == i) ; // BAD: but flagged by cs/constant-condition
40-
if (i != i) ; // BAD: but flagged by cs/constant-condition
39+
if (i == i) ; // $ Alert[cs/constant-condition] // BAD: but flagged by cs/constant-condition
40+
if (i != i) ; // $ Alert[cs/constant-condition] // BAD: but flagged by cs/constant-condition
4141

4242
CompareIdenticalValues c = null;
43-
c.Prop.Equals(c.Prop); // $ Alert
44-
Equals(c.Prop.Prop.Prop.Foo + 2, c.Prop.Prop.Prop.Foo + 2); // $ Alert
43+
c.Prop.Equals(c.Prop); // $ Alert[cs/comparison-of-identical-expressions]
44+
Equals(c.Prop.Prop.Prop.Foo + 2, c.Prop.Prop.Prop.Foo + 2); // $ Alert[cs/comparison-of-identical-expressions]
4545
Equals(c.Prop.Prop.Prop.Foo, c.Prop.Prop.Foo);
4646

4747
if (base.Bar == Bar) ;
48-
if (Bar == this.Bar) ; // $ Alert
49-
Equals(this); // $ Alert
48+
if (Bar == this.Bar) ; // $ Alert[cs/comparison-of-identical-expressions]
49+
Equals(this); // $ Alert[cs/comparison-of-identical-expressions]
5050

51-
if (1 + 1 == 2) ; // BAD: but flagged by cs/constant-condition
52-
if (1 + 1 == 3) ;
53-
if (0 == 1) ;
51+
if (1 + 1 == 2) ; // $ Alert[cs/constant-condition] // BAD: but flagged by cs/constant-condition
52+
if (1 + 1 == 3) ; // $ Alert[cs/constant-condition] // BAD: but flagged by cs/constant-condition
53+
if (0 == 1) ; // $ Alert[cs/constant-condition] // BAD: but flagged by cs/constant-condition
5454

5555
var a = new int[0];
56-
if (a[0] == a[0]) ; // $ Alert
56+
if (a[0] == a[0]) ; // $ Alert[cs/comparison-of-identical-expressions]
5757

58-
if (this.Bar[0] == Bar[1 - 1]) ; // $ Alert
58+
if (this.Bar[0] == Bar[1 - 1]) ; // $ Alert[cs/comparison-of-identical-expressions]
5959
if (this.Bar[0] == Bar[1]) ;
6060

61-
if (this.Prop[Foo] == Prop[this.Foo]) ; // $ Alert
61+
if (this.Prop[Foo] == Prop[this.Foo]) ; // $ Alert[cs/comparison-of-identical-expressions]
6262
if (this.Prop[0] == Prop[1]) ;
6363
}
6464

@@ -73,17 +73,17 @@ public void IsBoxed<T>(T x) where T : I
7373

7474
public void IsBoxedWrong1<T>(T x) where T : struct
7575
{
76-
ReferenceEquals(x, x); // $ Alert
76+
ReferenceEquals(x, x); // $ Alert[cs/comparison-of-identical-expressions]
7777
}
7878

7979
public void IsBoxedWrong2<T>(T x) where T : class
8080
{
81-
ReferenceEquals(x, x); // $ Alert
81+
ReferenceEquals(x, x); // $ Alert[cs/comparison-of-identical-expressions]
8282
}
8383

8484
public void IsBoxedWrong3<T>(T x) where T : Super
8585
{
86-
ReferenceEquals(x, x); // $ Alert
86+
ReferenceEquals(x, x); // $ Alert[cs/comparison-of-identical-expressions]
8787
}
8888

8989
public int this[int i] { get { return 0; } }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| CompareIdenticalValues.cs:20:20:20:25 | ... == ... | Condition always evaluates to 'true'. | CompareIdenticalValues.cs:20:20:20:25 | ... == ... | dummy |
2+
| CompareIdenticalValues.cs:39:13:39:18 | ... == ... | Condition always evaluates to 'true'. | CompareIdenticalValues.cs:39:13:39:18 | ... == ... | dummy |
3+
| CompareIdenticalValues.cs:40:13:40:18 | ... != ... | Condition always evaluates to 'false'. | CompareIdenticalValues.cs:40:13:40:18 | ... != ... | dummy |
4+
| CompareIdenticalValues.cs:51:13:51:22 | ... == ... | Condition always evaluates to 'true'. | CompareIdenticalValues.cs:51:13:51:22 | ... == ... | dummy |
5+
| CompareIdenticalValues.cs:52:13:52:22 | ... == ... | Condition always evaluates to 'false'. | CompareIdenticalValues.cs:52:13:52:22 | ... == ... | dummy |
6+
| CompareIdenticalValues.cs:53:13:53:18 | ... == ... | Condition always evaluates to 'false'. | CompareIdenticalValues.cs:53:13:53:18 | ... == ... | dummy |
Lines changed: 2 additions & 0 deletions
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

0 commit comments

Comments
 (0)