@@ -26,18 +26,21 @@ module Ast implements AstSig<Location> {
2626
2727 class AstNode = ExprParent ;
2828
29- private predicate skipControlFlow ( Expr e ) {
30- exists ( ConstCase cc | e = cc .getValue ( _) ) or
31- e .getParent * ( ) instanceof Annotation or
29+ private predicate skipControlFlow ( AstNode e ) {
30+ e .( Expr ) .getParent * ( ) instanceof Annotation or
3231 e instanceof TypeAccess or
3332 e instanceof ArrayTypeAccess or
3433 e instanceof UnionTypeAccess or
3534 e instanceof IntersectionTypeAccess or
36- e instanceof WildcardTypeAccess
35+ e instanceof WildcardTypeAccess or
36+ // Switch cases of the form `case e1 -> e2;` skip the ExprStmt and treat
37+ // the right-hand side as an expression. See `SwitchCase.getRuleExpression()`.
38+ any ( SwitchCase sc ) .getRuleExpression ( ) = e .( J:: ExprStmt ) .getExpr ( )
3739 }
3840
3941 AstNode getChild ( AstNode n , int index ) {
4042 not skipControlFlow ( result ) and
43+ not skipControlFlow ( n ) and
4144 result .( Expr ) .isNthChildOf ( n , index )
4245 or
4346 result .( Stmt ) .isNthChildOf ( n , index )
@@ -60,7 +63,9 @@ module Ast implements AstSig<Location> {
6063
6164 class BlockStmt = J:: BlockStmt ;
6265
63- class ExprStmt = J:: ExprStmt ;
66+ class ExprStmt extends J:: ExprStmt {
67+ ExprStmt ( ) { not skipControlFlow ( this ) }
68+ }
6469
6570 class IfStmt = J:: IfStmt ;
6671
0 commit comments