@@ -67,14 +67,21 @@ abstract class ConditionalCompletion extends NormalCompletion {
6767 abstract ConditionalCompletion getDual ( ) ;
6868}
6969
70+ /** Holds if node `n` has the Boolean constant value `value`. */
71+ private predicate isBooleanConstant ( AstNode n , Boolean value ) {
72+ n .( LiteralExpr ) .getTextValue ( ) = value .toString ( )
73+ or
74+ isBooleanConstant ( n .( ParenExpr ) .getExpr ( ) , value )
75+ }
76+
7077/**
7178 * A completion that represents evaluation of an expression
7279 * with a Boolean value.
7380 */
7481class BooleanCompletion extends ConditionalCompletion , TBooleanCompletion {
7582 BooleanCompletion ( ) { this = TBooleanCompletion ( value ) }
7683
77- override predicate isValidForSpecific ( AstNode e ) {
84+ private predicate isValidForSpecific0 ( AstNode e ) {
7885 e = any ( IfExpr c ) .getCondition ( )
7986 or
8087 any ( MatchArm arm ) .getGuard ( ) = e
@@ -84,7 +91,7 @@ class BooleanCompletion extends ConditionalCompletion, TBooleanCompletion {
8491 e = expr .getLhs ( )
8592 )
8693 or
87- exists ( Expr parent | this .isValidForSpecific ( parent ) |
94+ exists ( Expr parent | this .isValidForSpecific0 ( parent ) |
8895 parent =
8996 any ( PrefixExpr expr |
9097 expr .getOperatorName ( ) = "!" and
@@ -103,6 +110,15 @@ class BooleanCompletion extends ConditionalCompletion, TBooleanCompletion {
103110 )
104111 }
105112
113+ override predicate isValidForSpecific ( AstNode e ) {
114+ this .isValidForSpecific0 ( e ) and
115+ (
116+ isBooleanConstant ( e , value )
117+ or
118+ not isBooleanConstant ( e , _)
119+ )
120+ }
121+
106122 /** Gets the dual Boolean completion. */
107123 override BooleanCompletion getDual ( ) { result = TBooleanCompletion ( value .booleanNot ( ) ) }
108124
0 commit comments