Skip to content

Commit 1d7b434

Browse files
committed
Java: Exclude ExprStmt consistent with SwitchCase.getRuleExpression().
1 parent 9eeeb97 commit 1d7b434

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -58,7 +61,9 @@ module Ast implements AstSig<Location> {
5861

5962
class BlockStmt = J::BlockStmt;
6063

61-
class ExprStmt = J::ExprStmt;
64+
class ExprStmt extends J::ExprStmt {
65+
ExprStmt() { not skipControlFlow(this) }
66+
}
6267

6368
class IfStmt = J::IfStmt;
6469

0 commit comments

Comments
 (0)