Skip to content

Commit 0cd4340

Browse files
committed
C#: Address review comment: refactor last() predicate for ConstCase and TypeCase.
1 parent d5eacf8 commit 0cd4340

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

csharp/ql/src/semmle/code/csharp/controlflow/ControlFlowGraph.qll

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,33 +1272,24 @@ module ControlFlow {
12721272
// Case expression exits abnormally
12731273
result = lastConstCaseExpr(cc, c) and
12741274
not c instanceof NormalCompletion
1275-
or
1276-
// Case statement exits with any completion
1277-
result = lastConstCaseStmt(cc, c)
1278-
or
1279-
// Condition exists with a `false` completion
1280-
result = lastCaseCondition(cc, c) and
1281-
c instanceof FalseCompletion
1282-
or
1283-
// Condition exists abnormally
1284-
result = lastCaseCondition(cc, c) and
1285-
not c instanceof NormalCompletion
12861275
)
12871276
or
12881277
cfe = any(TypeCase tc |
12891278
// Type test exits with a non-match
12901279
result = lastTypeCaseNoMatch(tc, c)
1291-
or
1280+
)
1281+
or
1282+
cfe = any(CaseStmt cs |
12921283
// Condition exists with a `false` completion
1293-
result = lastCaseCondition(tc, c) and
1284+
result = lastCaseCondition(cs, c) and
12941285
c instanceof FalseCompletion
12951286
or
12961287
// Condition exists abnormally
1297-
result = lastCaseCondition(tc, c) and
1288+
result = lastCaseCondition(cs, c) and
12981289
not c instanceof NormalCompletion
12991290
or
13001291
// Case statement exits with any completion
1301-
result = lastTypeCaseStmt(tc, c)
1292+
result = lastCaseStmt(cs, c)
13021293
)
13031294
or
13041295
exists(LoopStmt ls |
@@ -1584,8 +1575,10 @@ module ControlFlow {
15841575
}
15851576

15861577
pragma [nomagic]
1587-
private ControlFlowElement lastConstCaseStmt(ConstCase cc, Completion c) {
1588-
result = last(cc.getStmt(), c)
1578+
private ControlFlowElement lastCaseStmt(CaseStmt cs, Completion c) {
1579+
result = last(cs.(TypeCase).getStmt(), c)
1580+
or
1581+
result = last(cs.(ConstCase).getStmt(), c)
15891582
}
15901583

15911584
pragma [nomagic]
@@ -1598,11 +1591,6 @@ module ControlFlow {
15981591
result = last(tc.getVariableDeclExpr(), c)
15991592
}
16001593

1601-
pragma [nomagic]
1602-
private ControlFlowElement lastTypeCaseStmt(TypeCase tc, Completion c) {
1603-
result = last(tc.getStmt(), c)
1604-
}
1605-
16061594
pragma [nomagic]
16071595
private ControlFlowElement lastLoopStmtCondition(LoopStmt ls, Completion c) {
16081596
result = last(ls.getCondition(), c)

0 commit comments

Comments
 (0)