File tree Expand file tree Collapse file tree
csharp/ql/test/query-tests
Language Abuse/SimplifyBoolExpr
standalone/Language Abuse/SimplifyBoolExpr Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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 |
You can’t perform that action at this time.
0 commit comments