@@ -94,13 +94,13 @@ class LogicalOrBinaryOpExprTree extends PreOrderTree instanceof BinaryExpr {
9494 // Edge from the last node in the lhs to the first node in the rhs
9595 last ( super .getLhs ( ) , pred , c ) and
9696 first ( super .getRhs ( ) , succ ) and
97- c .( BooleanCompletion ) .getValue ( ) = false
97+ c .( BooleanCompletion ) .failed ( )
9898 }
9999
100100 override predicate last ( AstNode node , Completion c ) {
101101 // Lhs. as the last node
102102 last ( super .getLhs ( ) , node , c ) and
103- c .( BooleanCompletion ) .getValue ( ) = true
103+ c .( BooleanCompletion ) .succeeded ( )
104104 or
105105 // Rhs. as the last node
106106 last ( super .getRhs ( ) , node , c ) // and
@@ -124,13 +124,13 @@ class LogicalAndBinaryOpExprTree extends PreOrderTree instanceof BinaryExpr {
124124 // Edge from the last node in the lhs to the first node in the rhs
125125 last ( super .getLhs ( ) , pred , c ) and
126126 first ( super .getRhs ( ) , succ ) and
127- c .( BooleanCompletion ) .getValue ( ) = true
127+ c .( BooleanCompletion ) .succeeded ( )
128128 }
129129
130130 override predicate last ( AstNode node , Completion c ) {
131131 // Lhs. as the last node
132132 last ( super .getLhs ( ) , node , c ) and
133- c .( BooleanCompletion ) .getValue ( ) = false
133+ c .( BooleanCompletion ) .failed ( )
134134 or
135135 // Rhs. as the last node
136136 last ( super .getRhs ( ) , node , c )
@@ -205,11 +205,11 @@ class IfExprTree extends PostOrderTree instanceof IfExpr {
205205 // Edges from the condition to the branches
206206 last ( super .getCondition ( ) , pred , c ) and
207207 (
208- first ( super .getThen ( ) , succ ) and c .( BooleanCompletion ) .getValue ( ) = true
208+ first ( super .getThen ( ) , succ ) and c .( BooleanCompletion ) .succeeded ( )
209209 or
210- first ( super .getElse ( ) , succ ) and c .( BooleanCompletion ) .getValue ( ) = false
210+ first ( super .getElse ( ) , succ ) and c .( BooleanCompletion ) .failed ( )
211211 or
212- not super .hasElse ( ) and succ = this and c .( BooleanCompletion ) .getValue ( ) = false
212+ not super .hasElse ( ) and succ = this and c .( BooleanCompletion ) .failed ( )
213213 )
214214 or
215215 // An edge from the then branch to the last node
@@ -272,6 +272,52 @@ class LoopExprTree extends PostOrderTree instanceof LoopExpr {
272272 }
273273}
274274
275+ class MatchArmTree extends ControlFlowTree instanceof MatchArm {
276+ override predicate propagatesAbnormal ( AstNode child ) { child = super .getExpr ( ) }
277+
278+ override predicate first ( AstNode node ) { node = super .getPat ( ) }
279+
280+ override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
281+ // Edge from pattern to guard/arm if match succeeds.
282+ pred = super .getPat ( ) and
283+ c .( MatchCompletion ) .succeeded ( ) and
284+ ( if super .hasGuard ( ) then first ( super .getGuard ( ) , succ ) else first ( super .getExpr ( ) , succ ) )
285+ or
286+ // Edge from guard to arm if the guard succeeds.
287+ last ( super .getGuard ( ) , pred , c ) and
288+ first ( super .getExpr ( ) , succ ) and
289+ c .( BooleanCompletion ) .succeeded ( )
290+ }
291+
292+ override predicate last ( AstNode node , Completion c ) {
293+ node = super .getPat ( ) and c .( MatchCompletion ) .failed ( )
294+ or
295+ last ( super .getGuard ( ) , node , c ) and c .( BooleanCompletion ) .failed ( )
296+ or
297+ last ( super .getExpr ( ) , node , c )
298+ }
299+ }
300+
301+ class MatchExprTree extends PostOrderTree instanceof MatchExpr {
302+ override predicate propagatesAbnormal ( AstNode child ) { child = super .getABranch ( ) .getExpr ( ) }
303+
304+ override predicate first ( AstNode node ) { first ( super .getExpr ( ) , node ) }
305+
306+ override predicate succ ( AstNode pred , AstNode succ , Completion c ) {
307+ // Edge from the scrutinee to the first arm.
308+ last ( super .getExpr ( ) , pred , c ) and succ = super .getBranch ( 0 ) .getPat ( )
309+ or
310+ // Edge from a failed match/guard in one arm to the beginning of the next arm.
311+ exists ( int i |
312+ last ( super .getBranch ( i ) , pred , c ) and
313+ first ( super .getBranch ( i + 1 ) , succ ) and
314+ c .( ConditionalCompletion ) .failed ( )
315+ )
316+ or
317+ exists ( int i | last ( super .getBranch ( i ) , pred , c ) and succ = this and completionIsSimple ( c ) )
318+ }
319+ }
320+
275321class MethodCallExprTree extends StandardPostOrderTree instanceof MethodCallExpr {
276322 override ControlFlowTree getChildNode ( int i ) {
277323 result = super .getReceiver ( ) and
0 commit comments