Skip to content

Commit 838e1f7

Browse files
committed
C#: Add some tests with incomplete type information.
1 parent 6d876f7 commit 838e1f7

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎csharp/ql/test/query-tests/Language Abuse/SimplifyBoolExpr/SimplifyBoolExpr.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@ void Fn()
4444
if (true != false) ;
4545
if (true && true) ;
4646
if (true || false) ;
47+
48+
bool? boption = false;
49+
if (boption == true) ; // GOOD. Cant be simplified like a regular bool
4750
}
4851
}

‎csharp/ql/test/query-tests/standalone/Language Abuse/SimplifyBoolExpr/SimplifyBoolExpr.cs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ class IncompleteNestedOperatorTest
5858
return lambda() || Local();
5959
}
6060
}
61+
62+
class Test
63+
{
64+
public class Container
65+
{
66+
public bool? Field;
67+
}
68+
69+
public void Fn()
70+
{
71+
bool? boption = false;
72+
if (boption == true) ; // GOOD. Can't be simplified like a regular bool
73+
74+
bool b = false;
75+
if (b ? boption : false) ; // GOOD. Can't be simplified like a regular bool
76+
77+
// Emulating incomplete type information by not declaring container explicitly.
78+
if (container.Field == true) ; // GOOD. Can't be simplified like a regular bool
79+
80+
if (b ? container.Field : false) ; // GOOD. Can't be simplified like a regular bool
81+
}
82+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#select
12
| SimplifyBoolExpr.cs:10:29:10:56 | !... | The expression '!(A == B)' can be simplified to 'A != B'. |
23
| SimplifyBoolExpr.cs:13:33:13:64 | !... | The expression '!(A == B)' can be simplified to 'A != B'. |
34
| SimplifyBoolExpr.cs:45:115:45:130 | !... | The expression '!(A == B)' can be simplified to 'A != B'. |
5+
| SimplifyBoolExpr.cs:78:13:78:35 | ... == ... | The expression 'A == true' can be simplified to 'A'. |
6+
| SimplifyBoolExpr.cs:80:13:80:39 | ... ? ... : ... | The expression 'A ? B : false' can be simplified to 'A && B'. |
7+
testFailures
8+
| SimplifyBoolExpr.cs:78:13:78:35 | The expression 'A == true' can be simplified to 'A'. | Unexpected result: Alert |
9+
| SimplifyBoolExpr.cs:80:13:80:39 | The expression 'A ? B : false' can be simplified to 'A && B'. | Unexpected result: Alert |

0 commit comments

Comments
 (0)