@@ -31,18 +31,21 @@ module Ast implements AstSig<Location> {
3131
3232 class AstNode = ExprParent ;
3333
34- private predicate skipControlFlow ( Expr e ) {
35- exists ( ConstCase cc | e = cc .getValue ( _) ) or
36- e .getParent * ( ) instanceof Annotation or
34+ private predicate skipControlFlow ( AstNode e ) {
35+ e .( Expr ) .getParent * ( ) instanceof Annotation or
3736 e instanceof TypeAccess or
3837 e instanceof ArrayTypeAccess or
3938 e instanceof UnionTypeAccess or
4039 e instanceof IntersectionTypeAccess or
41- e instanceof WildcardTypeAccess
40+ e instanceof WildcardTypeAccess or
41+ // Switch cases of the form `case e1 -> e2;` skip the ExprStmt and treat
42+ // the right-hand side as an expression. See `SwitchCase.getRuleExpression()`.
43+ any ( SwitchCase sc ) .getRuleExpression ( ) = e .( J:: ExprStmt ) .getExpr ( )
4244 }
4345
4446 AstNode getChild ( AstNode n , int index ) {
4547 not skipControlFlow ( result ) and
48+ not skipControlFlow ( n ) and
4649 result .( Expr ) .isNthChildOf ( n , index )
4750 or
4851 result .( Stmt ) .isNthChildOf ( n , index )
@@ -63,7 +66,9 @@ module Ast implements AstSig<Location> {
6366
6467 class BlockStmt = J:: BlockStmt ;
6568
66- class ExprStmt = J:: ExprStmt ;
69+ class ExprStmt extends J:: ExprStmt {
70+ ExprStmt ( ) { not skipControlFlow ( this ) }
71+ }
6772
6873 class IfStmt = J:: IfStmt ;
6974
0 commit comments